pyscripter与python的关系_Python(pyscripter)

def main():

pass

if __name__ == '__main__':

main()

import random # imports random

# Your 2 while loops were not indented causing them not to know what the attempt variable, made in the GuessingGame function was.

def GuessingGame (): # creating def function for GuessingGame

yes = ['y', 'Y', 'Yes', 'yes'] # setting variables

rng = random.Random ()

numbertoguess = rng.randrange (1,10) # setting random number between 1 and 10

correctguesses = 0

winpercent = 0

attempts = 0

name = raw_input('What is your name? ') # asks user for name and introduces the game (inputs used in strings must be raw.)

print('Nice to meet you', name ,'! I am going to pick a random number and you will have 3 tries to guess it.'

'Good luck!')

while attempts < 3: # creates a function

guess = int(input('Guess the number I have chosen between 1 and 10. '))

attempts += 1

if guess == numbertoguess: # tells user if guess is right

print('Great guess, youre right', name, '!')

correctguesses += 1 # adds on to correct guesses

winpercent = float((correctguesses*100)/attempts)# determines percent of correct answers

print ('You have' , correctguesses, 'correct guesses!')

print ('You are right', winpercent, 'of the time.')

elif guess > numbertoguess: # tells if guess is too high

print('The number is lower than', guess, "!")

elif guess < numbertoguess: # tells if guess is too low

print('The number is higher than', guess, "!")

else: # tells when you have lost

print('Wrong, the number was', numbertoguess, '!')

print ('You have' , correctguesses, 'correct guesses!')

print ('You are right', winpercent, 'of the time.')

gameover = raw_input("Do you want to play again? Yes or No? ")

while gameover is 'Yes' or 'yes': GuessingGame () #oportunity to play again

else: exit() # ends games

print ('The program will now terminate. Goodbye.')

GuessingGame () # calls game`enter code here`

有两个原因导致代码无法工作。首先,我们不知道是什么导致了游戏中的变量。第二个原因是,如果要在字符串中使用输入,则必须使用raw_input(),而不是纯input()。我希望这有帮助!在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值