我想生成1到6之间的数字并让用户猜它。 if input == variable:
中的检查功能无效。
global count
count = 0
def guess():
a = random.randint(1,6)
print (a)
ffs =input ("whats my nr?")
if ffs == (a):
print ("Correct")
sys.exit()
else:
global count
print ("guess again")
count +=1
print ("you have attempts remaining")
def mainz():
while count < 6:
guess()
mainz()
答案 0 :(得分:0)
global count
count = 0
def guess():
a = random.randint(1,6)
print (a)
ffs =input ("whats my nr?")
if ffs == str(a):
print ("Correct")
sys.exit()
else:
global count
print ("guess again")
count +=1
print ("you have attempts remaining")
def mainz():
while count < 6:
guess()
mainz()
需要str(a)
答案 1 :(得分:0)
首先,您的mainz()
函数和mainz()
调用都在guess()
函数中,但我猜这只是格式化错误。真正的错误在于输入返回一个你想要与int进行比较的字符串。我建议只是这样做:
ffs = int(input("What's my nr? ") )