如果字符数不是11,如何停止此代码重复打印消息?我希望它重复循环,直到键入正确数量的字符,但它不会这样做。
phone = input(str("enter the phone number"))
while len(phone) !=11:
if len(phone)>11:
print("you entered too many numbers")
elif len(phone)<11:
print("you entered too few numbers")
else:
print ("correct phone number length")
答案 0 :(得分:0)
如果电话号码的长度不是11个号码,您可以尝试再次提示用户输入。
while True:
phone = input(str("enter the phone number"))
if len(phone) > 11:
print("you entered too many numbers")
elif len(phone) < 11:
print("you entered too few numbers")
else:
break
print ("correct phone number length")
答案 1 :(得分:0)
while True:
phone = str(input("enter the phone number"))
if len(phone) == 11:
break
if len(phone)>11:
print("you entered too many numbers")
elif len(phone)<11:
print("you entered too few numbers")