我很难理解为什么当我输入的球员选择它继续循环,即使他们输入正确的战士类型。如果有人能帮忙,我将不胜感激。在
playerchoice = ""
confirmwarrior = ""
warriortype = ("swordsman", "wizard", "archer", "healer")
while playerselection != warriortype:
playerselection = input("""
please select the type of warrior you wish to be:
- Swordsman
- Wizard
- Archer
- Healer
""").lower()
else:
print("you have entered and incorrect Warrior, please try again")
print("your chosen Warrior is",playerselection)
while confirmwarrior != "y":
confirmwarrior = input("""
are you happy with this Warrior?
stefan
y - yes
N - No
""")
confirmwarrior.lower()
print("you have Chosen to be", playerselection)
我想这是你的状况
您将比较用户输入的字符串作为输入,它将始终是一个字符串,例如“剑客”,并比较它是否与包含多个字符串的元组(始终为true)相等。在
我想你要找的条件是
当playerselection等于元组中的某个项时,它将变为false。在
以下是正确工作的修改后的代码:
编辑:当你在选择了一个战士后回答“不”时,下面的代码会重新询问你想成为哪种类型的战士:
^{pr2}$相关问题 更多 >
编程相关推荐