我是Python的完全入门者,请原谅我缺乏知识,但是我正在创建一个游戏,其中有3个框-x,y和z-每个都有奖。玩家必须选择其中之一,然后显示其余2个之一。然后,玩家可以选择交换盒子。如果他们选择“是”,则会显示框内的内容。
在我的代码中,无论我输入什么内容,它都会运行第一个if语句。如果有帮助,我会使用Pycharm社区版。如果有人可以帮助我,那就太好了。谢谢。
我的代码:
x = "a million pounds"
y = "nothing"
z = "a car"
print("Welcome to the Prize Show hosted by yours truly - Shehroz Khan")
choice_1 = input("There are 3 boxes: X, Y and Z. Each contain something that you can win."
"\nOne of them has " + z + ", another has " + x + " and one has " + y + "."
"\nPick one of the three. ")
if choice_1 == "x" or "X":
print("You chose X! I will now tell you what is in one of the remaining boxes."
"\nThen you can pick if you would like to switch boxes."
"\nIn box Y, there was..." + y)
swap_x = input("Would you like to swap your choice? Please type \"Yes\" or \"No\". ")
if swap_x == "yes" or "Yes":
print("Your choice is now box Z. In box X was... " + x + "\nCongratulations - in box Z was " + z + "!"
"\nYou could have gotten luckier if you stayed"
" with your choice but you can't be upset with a"
" prize!")
elif swap_x == "no" or "No":
print("Your choice is still box X. In box Z was... " + z + "\nCongratulations - in box X was. " + x + "!"
"\nYour luck is amazing! "
"\nYou have won the grand prize!")
elif choice_1 == "y" or "Y":
print("You chose Y! I will now tell you what is in one of the remaining boxes."
"\nThen you can pick if you would like to switch boxes."
"\nIn box z, there was..." + z + "!")
swap_y = input("Would you like to swap your choice? Please type \"Yes\" or \"No\". ")
if swap_y == "yes" or "Yes":
print("Your choice is now box X. In box Y was... " + y + "\nCongratulations - in box X was" + x + "!"
"\nYou saved yourself there!"
"\nNow you can enjoy your prize of " + x + "!")
elif swap_y == "no" or "No":
print("Your choice is still box Y. In box X was... " + x + "\nUnlucky your trash kid - in box Y was. " + y + "!"
"\nYour luck is trash kid! "
"\nYou have won the poopy prize!")
elif choice_1 == "z" or "Z":
print("You chose Z! I will now tell you what is in one of the remaining boxes."
"\nThen you can pick if you would like to switch boxes."
"\nIn box Y, there was..." + y + "!")
swap_z = input("Would you like to swap your choice? Please type \"Yes\" or \"No\". ")
if swap_z == "yes" or "Yes":
print("Your choice is now box X. In box Z was... " + z + "\nCongratulations - in box X was" + x + "!"
"\nNow you can enjoy your prize of " + x + "!")
elif swap_z == "no" or "No":
print("Your choice is still box Z. In box X was... " + x + "\nCongratulations - in box Z was " + z + "!"
"\nYou could have gotten luckier if you stayed"
" with your choice but you can't be upset with"
" a new"
" prize!")