我玩骰子有问题。每次我运行它都会说不正确,即使我猜对了数字。这是代码,还有我什么时候做对的截图:https://gyazo.com/87400aab5747a05c77415a816952b26d
import random
ask = input(": ")
for i in range(1):
dice = random.randint(1, 6)
print(dice)
if ask == random:
print("correct")
else:
print("incorrect")
Tags:
这可能是因为您读入了一些默认情况下是类型字符串的内容,而您的数字是整数数据类型。所以“6”不等于6。如果我是对的,你应该在比较之前做一些转换。你知道吗
如果将
ask
转换为整数,它将正常工作:相关问题 更多 >
编程相关推荐