0

I’m sure my question is somewhat easy but I am new to programming and would love some help :). The project is to create an escape room with three objects and depending on what was done prior, the player should be able to perform different tasks.

For example, in my escape room I have a pumpkin, a sign and box. When the sign lights up, it shows a coin shaped circle on the box. Inside the pumpkin there’s a coin, that should be places on top of the box so it can open. The problem is, if the user first chooses to look at the box, they will see nothing. Only when the user chooses to look at the sigg, to turn on the sign and then to examine the box they will be able to see the circle. Moreover, they will only be able to place the coin on top if they had already smashed the pumpkin.

So I could make my code a lot of if statements (basically like:

    if pumpkin_action == ‘smash’:
        if box_action == ‘put coin on box’:
            print(“You placed the coin on the box and BAM, the box opened revealing the key.”)
    Elif pumpkin_action != ‘smash’:
        if box_action == ‘examine box’: #since user wont even know the coin exists yet  
             print(“Weird coin-shaped circle on it. Wonder what that does…”)

But there are sooo many different possibilities of choices that the user can choose like if sign isn’t turned on they cant see anything on the box etc. So i was wondering if there’s something I can do that would make the code more compact than never ending if statements. Thank you!

anna
  • 1
  • 1
  • 1
    `=` is not a valid python [comparison operator](https://www.w3schools.com/python/gloss_python_comparison_operators.asp). Did you mean `==` – It_is_Chris Oct 17 '22 at 19:34
  • For choosing amongst (n) multiple options, you might be interested in Python's match/case syntax: https://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python – Jeremy Friesner Oct 17 '22 at 19:42
  • The keyword `elif` is spelled `elif` with a lowercase e, not `Elif` with a capital E. `elif pumpkin_action != 'smash'` can just be `else:`; the condition doesn't need to be specified if it's the opposite of the if that the else is attached to. – Nathan Mills Oct 18 '22 at 00:02

0 Answers0