guess=0和while guess !是你原来的呀,我没有改;
你说的还是原来那样是不是指第一种,第一种确实不会提醒用户“Please give an integer!”,因为第一种只是把密码检测由数字改为字符串,用户输入非整数就不会报错,后面两种就可以满足你的需求了吧。
刚刚看了一下发现第三种有一个小错误,第15行guess = int(temp)应该改为guess = int(temp2),不好意思。
另外,你的代码思路应该是先让用户循环输入正确的用户名,然后再循环输入正确的密码,对吧?但你原来的写法(包括我昨晚的三段代码,没有改你的思路),如果用户在输入用户名阶段输入了110110110110,就会跳出循环。我觉得要实现你的想法,像下面这样可能会更好,不必在循环里套循环,直接分成两段,更明晰。
while True:
print("welcome BayMax Secret")
temp=input("Please input account number:")
try:
guess = int(temp)
except ValueError:
print('Please give an integer!')
continue
if guess == 1637000313:
print("Correct account number:1637000313")
break
else:
print("..who are you..Your invasion has informed the owner")
while True:
temp2=input("Please enter your password:")
try:
guess = int(temp2)
except ValueError:
print('Please give an integer!')
continue
if guess == 110110110110:
print ("welcome")
break
else:
print ("Sorry, the password is wrong. Call 小甲鱼 to get the universal password")
By the way, 我不是老师,也是小白一枚~~