如何添加输入循环?

时间:2015-09-22 17:28:01

标签: python loops input

classes = input("There are three types of classes in this game. Warrior, Wizard and Hunter. Pick one.")

if classes == "Warrior" or "Wizard" or "Hunter":
    print ("Good choice.. the "+classes+" will dominate your opponents!")
else:
    print ("That's not a class! Pick again!")

#基本上,我想添加一个循环,以便它再次提出问题。

请记住我使用的是Python-3

2 个答案:

答案 0 :(得分:0)

characters = ("Warrior", "Wizard", "Hunter")

while True:
  classes = input("There are three types of classes in this game. Warrior, Wizard and Hunter. Pick one.")
  if classes in characters:
    break
  else:
    print ("That's not a class! Pick again!")

print ("Good choice.. the "+classes+" will dominate your opponents!")

答案 1 :(得分:0)

classes = input("There are three types of classes in this game. Warrior, Wizard and Hunter. Pick one.\n")

while classes not in ("Warrior", "Wizard", "Hunter"):
  print ("That's not a class! Pick again!\n")
  classes = input("There are three types of classes in this game. Warrior, Wizard and Hunter. Pick one.\n")

print ("Good choice.. the "+classes+" will dominate your opponents!\n")