This question already has an answer here:
I am a complete beginner to Python so excuse my lack of knowledge but I am creating a game where there are 3 boxes - x, y, and z - each one with a prize. The player has to pick one of them and then one of the remaining 2 get revealed. The player is then given a choice to swap boxes. If they choose yes, it is then revealed what was inside the box.
In my code, no matter what input I put in, it runs the first if statement. I use Pycharm community edition if that makes a difference. If anybody could help me that would be great. Thanks.
My Code:
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!")
Aucun commentaire:
Enregistrer un commentaire