Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python重复动作_Python_Python 3.x_While Loop_Repeat - Fatal编程技术网

Python重复动作

Python重复动作,python,python-3.x,while-loop,repeat,Python,Python 3.x,While Loop,Repeat,我有一个包含字符串的列表 animalList=['ASLAN', 'KAPLAN', 'KOPEK', 'KEDI'] descLion = ( 'it is called lion....') descTiger = (' it is called tiger....') 我要求用户输入其中一个,并检查输入错误 questOne = input("Enter the name of the animal: ") questOne = questOne.upper() while quest

我有一个包含字符串的列表

animalList=['ASLAN', 'KAPLAN', 'KOPEK', 'KEDI']
descLion = ( 'it is called lion....')
descTiger = (' it is called tiger....')
我要求用户输入其中一个,并检查输入错误

questOne = input("Enter the name of the animal: ")
questOne = questOne.upper()
while questOne not in animalList: 
    questOne = input("Whatch out for typos Try again: ")
    questOne = questOne.upper()
else:
    print(questOne + ' IT IS')
我不明白的是,我想让我的代码不断地询问动物的名字,检查拼写错误,打印相关的描述,然后重复这个动作。我试过类似的东西

while questOne == animalList[0]:
    print (descLion)
    questOne = input("Enter the name of the animal: ")
    questOne = questOne .upper()

while questOne == animalList[1]:
    print (descTiger)
    questOne = input("Enter the name of the animal: ")
    questOne = questOne.upper()
只有当用户输入按列表顺序排列时,这种代码才起作用。我希望用户能够随机输入。

您希望使用“while True”。例如:

while True:
    name = input("Enter your name: ")
    print("Hi, {}!".format(name))
    print("What about now?")

我真不敢相信会那么容易。谢谢!