print("Hello there " + str(name) + ", are you ready for your
adventure? Y/N")
adventure = input()
while adventure.lower() not in ("y", "n"): # <<<<< This line changed
print(str(name) + " ,that's not a choice. I'll ask again, are
you ready for your adventure? Y/N")
adventure = input()
if adventure.lower() == "n":
print("Cowards take the way out quickly.")
breakpoint
else:
print("Come, you will make a fine explorer for the empire!")
adventure = input("Hello there {}, are you ready for your adventure? Y/N".format(name)) #Added prompt to input, using string formatting.
while adventure.lower() not in ("y", "n"): # <<<<< Check input against tuple, instead of using `or` statement
adventure = input(" {}, that's not a choice. I'll ask again, are you ready for your adventure? Y/N".format(name)) #Same as first line
if adventure.lower() == "n":
print("Cowards take the way out quickly.")
break
else:
print("Come, you will make a fine explorer for the empire!")
将if语句更改为:
这是由于Python3中的比较是如何完成的。见here
您可以对代码进行一些其他修复:
见usage of python input command,string formatting
相关问题 更多 >
编程相关推荐