这是一个数字游戏,我无法发现错误


from fileinput import close

从随机导入随机,随机

print('Do you want to play a game?')
input1 = input("yes or no? ")
if input1 == "yes" or input1 == "Yes":
print("You have 3 tries to guess a random integer between 0-10. If you guess right 
you win. If not I do. Ready?")
import random
def repeat():
number = random.randint(1,10)
print(number)
guess1 = input('Your first guess: ')
if guess1 == number:
print('You are correct! You only needed one try!')
else:
print('Wrong two tries left!')
guess2 = input('Your second guess: ')
if guess2 == number:
print('You are correct! You needed two tries!')
else:
print('Wrong one try left!')
guess3 = input('Your third and last guess: ')
if guess3 == number:
print('You are correct! It took you all three tries!')
else:
print('You are wrong! You lost! The number was:')
print(number)
input2 = input('Do you want to play again? Yes or No? ')
if input2 == 'Yes' or 'yes':
repeat()
else:
close()

其他:关闭((repeat((

我不知道错误在哪里,但当我猜对数字时,它仍然说错了。

由于默认输入类型为字符串,因此需要将所有猜测转换为整数进行比较。

from fileinput import close
from random import Random, random
print('Do you want to play a game?')
input1 = input("yes or no? ")
if input1 == "yes" or input1 == "Yes":
print("You have 3 tries to guess a random integer between 0-10. If you guess right you win. If not I do. Ready?")
import random
def repeat():
number = random.randint(1,10)
print(number)
guess1 = int(input('Your first guess: '))
if guess1 == number:
print('You are correct! You only needed one try!')
else:
print('Wrong two tries left!')
guess2 = int(input('Your second guess: '))
if guess2 == number:
print('You are correct! You needed two tries!')
else:
print('Wrong one try left!')
guess3 = int(input('Your third and last guess: '))
if guess3 == number:
print('You are correct! It took you all three tries!')
else:
print('You are wrong! You lost! The number was:')
print(number)
input2 = input('Do you want to play again? Yes or No? ')
if input2 == 'Yes' or 'yes':
repeat()
else:
close()
else: close() repeat()

最新更新