Python Forum

Full Version: Syntax error for a reason I don't understand
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I receive a syntax error on the line if a == b: (line 46) I don't understand why. I believe that all the indentations are correct.

import random

ans = input("Welcome to escape the cave text adventure would you like to play? ")
if ans == "yes":
    inventory = []
    print ("")
    ans = input("You find yourself stuck in the middle of a cave with no obvious escape. You have two options, you go left or you go right: ")
    if ans == "left":
        print("You walk down a dark path and stumble into a pair of batteries, you pick them up. ")
        inventory.append("batteries")
        ans = input("You look up to see a dangling rope leading to an opening above you, you also see a path ahead of you which way do you go? (rope/path) ")
        if ans == "rope":
            print ("The rope snapped and fell, you died. GAME OVER")
        elif ans == "path":
            ans = input("You peer around the corner to see a old rickety bridge, do you want to cross it? ")
            if ans == "yes":
                ans = input("You cross the bridge safely and advance towards a glowing light, you get near and it is a fire, you must not be alone in the cave. Do you investigate the fire? ")
                if ans == "yes":
                    print("You feel a pair of hands on your back as you neel near the fire, you try to fight back but you can't and you are pushed into the fire. You die. GAME OVER")
                elif ans == "no":
                    ans = input("You realise that you can't be alone in the cave, you pannick and fall of a ledge injuring your leg. Do you give up and die or battle on? (give up/battle on) ")
                    if ans == "give up":
                        print ("You give up and die. GAME OVER")
                    elif ans == "battle on":
                        print ("You try but as you walk your leg gives way and you smash your head against a rock. You die. GAME OVER.")
            elif ans == "no":
                ans = input("You notice a hole in the ground and see it as the only other way to go. You drop down and fall into some dangerous rapids that drag you under. Do you sink or swim? ")
                if ans == "swim":
                    print("You try to swim but your struggle leads to you death. GAME OVER")
                elif ans == "sink":
                    print("You get sucked under and everything goes black. You wake up spluttering and on a ledge adjacent to the rapids. Lying there is a torch but with no batteries if you have batteries you can put them in.")
                    if ("batteries") in inventory:
                        inventory.remove("batteries")
                        inventory.append("torch")
                        ans == input("You shine your torch and see a bloody monster. Do you attack or run? ")
                        if ans == "run":
                            print("You tried to run but you tripped and fell leaving yourself defensless against the monster. GAME OVER")
                        elif ans == "attack":
                            ans = input("You attack and defeat the monster. You walk on, shining your torch, you see a glistening diamond sitting on a ledge. Do you take it? ")
                            if ans == "yes":
                                inventory.append("diamond")
                                ans = input("You walk along and on the wall you spot a machine asking you to guess a number between 1 and 5 for a reward. Do you play? ")
                                if ans == "yes":
                                    a = (random.randint(1,5))
                                    b = int(input("Enter a number between 1 and 5: ")
                                    if a == b:
                                        print ("that is the correct number, here is an emerald.")
                                        inventory.append("emerald")
                                        ans = input("You carry on walking and you bump into a shading looking man. He asks you if you have anything you could trade in exchange for your freedom. Do you want to trade? ")
                                        if ans == "yes":
                                            input("You can trade", inventory, "what do you choose? ")
                                            in ans in inventory:
                                            print("The man geatfully accepts your trade and shows you the way out the cave. CONGRATULATIONS, YOU WON!")
                                        else:
                                            print("That is the wrong number, the floor opens up beneath you. You die. GAME OVER")
                                    elif ans == "no":
                                        ans = input("You walk along and on the wall you spot a machine asking you to guess a number between 1 and 5 for a reward. Do you play? ")
                                            if ans == "yes":
                                            a = (random.randint(1,5))
                                            b = int(input("Enter a number between 1 and 5: ")
                                            if a == b:
                                                print ("that is the correct number, here is an emerald.")
                                                inventory.append("emerald")
                                                ans = input("You carry on walking and you bump into a shading looking man. He asks you if you have anything you could trade in exchange for your freedom. Do you want to trade? ")
                                                if ans == "yes":
                                                    input("You can trade", inventory, "what do you choose? ")
                                                    if ans in inventory:
                                                    print("The man geatfully accepts your trade and shows you the way out the cave. CONGRATULATIONS, YOU WON!")
                                                else:
                                                    print("That is the wrong number, the floor opens up beneath you. You die. GAME OVER")
                               

    
 b = int(input("Enter a number between 1 and 5: ")
there is two opening brackets and only one closing