【发布时间】:2023-01-22 11:13:38
【问题描述】:
现在,我有它,所以它会打印它选择的随机数。但是,无论我是错还是对,它总是说我错了。
这是我的代码:
import random
amount_right = 0
number = random.randint(1, 2)
guess = input
print(number)
print(
"welcome to this number guessing game!! I am going to think of a number from 1-10 and you have to guess it! Good luck!")
input("enter your guess here! ")
if guess != number:
print("Not quite!")
amount_right -= 1
print("you have a score of ", amount_right)
else:
print("good Job!!")
amount_right += 1
print("you have a score of ",amount_right,"!")
我做错什么了?如果有任何帮助,我正在使用 Pycharm。
我尝试检查我的缩进,我尝试切换哪些行是 if 和 else 语句(第 13 - 21 行),我尝试将第 18 - 21 行更改为 elif: 语句
【问题讨论】:
-
guess = input不要求任何输入,而是将输入函数分配给猜测哪个不是您想要的。 -
输入在错误的行,你必须接受输入并直接存储它
-
你要
guess = int(input("enter your guess here! "))