我正在用Python创建一个程序,要求用户输入他们的名字。 我也试图通过让用户输入两次来验证这一点,程序只有在用户正确输入两次名称时才会运行。
请查看下面的代码,请向我提供任何建议
from random import randint
name3 = 1
while name3 == -1:
name = input("Please enter your name ")
name1 = input("Please enter your name again for verification ")
if name == name1 :
print("you may now start the quiz")
else:
print (" The two names are different please enter you your name again")
name3 = name3 + 1
答案 0 :(得分:0)
嗨,这是一个检查用户名并限制重试次数的简单模型
name = raw_input("Please enter your name ")
name1 = raw_input("Please enter your name again for verification ")
retry_count = 0
while (name != name1):
retry_count += 1
print ("The two names are different please enter you your name again!")
name = raw_input("Please enter your name ")
name1 = raw_input("Please enter your name again for verification ")
if (retry_count > 3 ):
break
if (retry_count > 3):
print("Too many retry!")
# do something
else:
print("you may now start the quiz")