Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Stuck in a conditional program

print("Enter your name:") name_input = input(">>")

print("Welcome {} to the game of choice made by Mayank Shah".format(name_input))

print("There are 3 doors and pick #1 or #2 or #3 ") door_input = input(">>")

if door_input == "1" or "#1": print("There is a witch standing besides you.") print("""You have 3 options.

  1. Ask her to see your future.
  2. Tell her to get lost.
  3. Beat her like anything.""")

    witch_input = input(">>")

    if witch_input == "1" : print("She will see your future by taking some of your blood.") print("Select from y/n to either see your future or not")

    future_input = input(">>")
    if future_input == "y" or "Y":
        print("You will die after 6 months and 10 days")
        print("""You die after 6 months and 10 days.

    'Game Over'""" ) elif future_input == "n" or "N": print("""Witch killed you for not telling her tell your future.\n 'Game Over'""")

        print("Invalid option.")

    elif witch_input == "2" : print("""She will not take any time to kill you as soon as you say those words\n 'Game Over'""")

    elif witch_input == "3" : print("""She will say some spell and you will burn into ashes\n 'Game Over'""") else: print("Invalid option. Try again") pass

Whenever I input "n" from Select from y/n to either see your fulture or not It always print You will die after 6 months and 10 days You die after 6 months and 10 days. 'Game Over'

while the o/p should be Witch killed you for not telling her tell your fulture 'Game Over'

1 Answer

You recognized the problem correctly, conditional statement is messing up.

So here is how if works for multiple conditions:

if  condition1 or condition2 and condition3:
    do something;

Here the condition is a complete condition, for example in your case:

condition1--> future_input == "y"  -->true if var is "y"
condition2-->  "Y": --> always true.

I am sure that you understand now.

so correct way is:

if future_input=="y"  or  future_input=="Y":
    do something.