我刚开始编程的几周。我试图做一个函数,要求用户输入,检查输入是否是字母,如果是字母,那么我想打破while循环
如果我运行脚本并在输入中输入正确的类型,它就会中断并正常工作。如果我故意在输入字段中输入一个数字,当我重新输入正确的类型时,它不会跳出循环
你知道我做错了什么吗
def wallType():
wall_type = input("What type of wall was the route on? ")
while wall_type:
#if there is text in the input,instead of an alphanumeric, then tell them they must put in a number.
if str.isalpha(wall_type):
return wall_type
else:
print("You entered a number, you must enter a word. Try again. ")
wallType()
将代码放入
while True
循环中。当接收到的输入按字母顺序排列时,使用break
跳出while
循环。否则再次循环以请求输入相关问题 更多 >
编程相关推荐