from random import randrange
A = input ("enter number ")
B = randrange (1,10)
B = int (B)
A = int (A)
while A != B :
B = randrange(1, 10)
if A == B :
print ("you guessed the number")
elif A != B :
input ("incorrect number try again ")
这是我的代码,我想限制用户只能输入3次
答案 0 :(得分:0)
您可以在每次输入数字时进行计数并减少计数。
from random import randrange
A = input ("enter number ")
B = randrange (1,10)
B = int (B)
A = int (A)
counter = 3
while A != B and counter:
counter -= 1
B = randrange(1, 10)
if A == B :
print ("you guessed the number")
elif A != B :
input ("incorrect number try again ")