我正在练习刷新我的python能力,因为去年我参加了这个课程。这是我想做的。我希望用户在PHONE字段中输入整数,只要在字段中输入任何其他TYPE,并且只输入整数时,迭代应该中断。
d = 0
done = 2
while done != "quit":
print ""
print ""
print "Please, fill in the following:"
print "Type your Name, then press enter."
name= raw_input("NAME >> ")
print "Type your First Name, then press enter."
fname= raw_input("FIRST NAME >>: ")
print "Type your Phone Number, then press enter."
tel= input("+509-")
print "e-mail address"
mail= raw_input("Ex: someone@domain.com >>: ")
print "Your address."
address= raw_input(" Address>>: ")
答案 0 :(得分:0)
我不知道这是否是最理想的解决方案,也许这对你来说已经很明显了,但这是我唯一知道的。您还可以为有效电话号码添加更多标准,例如位数。
tel = "meh"
validChars = '+-0123456789'
valid = False
while not valid:
print("Type your Phone Number, then press enter.")
tel= input("+509-")
valid = True
for char in tel:
if not char in validChars:
valid = False
break