我正在创建一个简单的交互式故事游戏,我要求用户输入并向他们显示一些句子。我想做的是询问用户这些句子来自哪里,以及他们是否输入了int而不是string。我想在用户不输入int的情况下反复询问它们来自哪里。我已经尝试了if和while循环,但似乎不起作用
import time
name = input("what is your name? ")
def greeting (name):
print("hhhmmm..... is that so?")
time.sleep(0)
x = input("Well " + name + " where have you been all these years?")
place_char = ""
while True:
if x == place_char:
break
# I want to keep asking for location until the user put a string or char not a number
print("please enter a location ")
print("So " + name + " you're telling me that you've been at " + x + " this entir time?")
greeting(name)
1条答案
按热度按时间kx1ctssn1#
一种方法是使用
isalpha()
返回True
,如果字母表中的所有字符:如果返回
False
,则请求新的输入并继续while循环。