How do you make sure that indented if statements still trigger even if the first statement is satisfied?

Question:

My game seems to just stop after module 1 if I survive and I can’t see what the problem is. The game is supposed to go to each part one after the other. However, when you survive the module, it does not continue. Here is the code:

#CAVEGAME
#Import
import random
import pickle
#Introduction
print("--------CaveGame V.4.1----------")
print("Credits - Rhys")
#Name loading
account_name = pickle.load(open( "caveuser1.pickle", "rb" ))
if account_name == 'Rhys':
 print("Welcome Rhys. Dev mode active")
elif account_name == 'Dev':
        print("Welcome developer. Dev mode active")
elif account_name == 'Mannat':
        print("You are not authorised to access this game.")
        quit()
elif account_name == 'Tammana':
 print("You are not authorised to access this game.")
 quit()
elif account_name == 'Yameen':
        print("You are not authorised to access this game - YAMEEN. ")
        quit()
elif account_name == 'CroissantMafia':
 print("Weclome Croissant Disciples. Go to this link for the code: https://github.com/DominionGaming/CaveGame")
else:
  print("Welcome to CaveGame")
#Stats
health = 20
damage = 1.5
points = 0
#PART1
print(account_name, "you are travelling down a cave and come to a fork in the cave. There are two paths - which do you choose?")
guess = int(input("Make a guess"))
tnl1 = random.randint(1,2)
if guess == tnl1:
        print('You survived')
        points = points + 50
elif guess != tnl1:
        print("You found a drakon")
        drakon1_health1 = 6
        drakon1_health2 = drakon1_health1 - damage
        drakon1_damage = 0.5
        health = health - drakon1_damage
        print("Your health is",health, "and the drakon's health is", drakon1_health2)
        health = health - drakon1_damage
        print("The drakon is defeated and your health is", health)
        points = points - 50
    #PART2
        print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. There are two paths - which do you choose?")
        guess2 = int(input("Make a guess"))
        tnl2 = random.randint(1,2)
        if guess2 == tnl2:
            print('You survived')
            print("You recieved a combat upgrade. You now deal more damage")
            points = points + 50
            damage = damage + 2
        elif guess2 != tnl2:
            print("A wave of fire rolls through the tunnel. You lose 5 health")
            health = health - 5
            points = points - 50
    #PART3
            print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
            guess3 = int(input("Make a guess"))
            tnl3 = random.randint(1,3)
            if guess3 == tnl3:
                print('You survived')
                print("You recieved a health upgrade.")
                health = health + 1.4
                points = points + 50
            elif guess3 != tnl3:
                 print("There was a cave in. You lost")
                 points = points - 50
                 quit()
    #PART4
                 print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
                 guess4 = int(input("Make a guess"))
                 tnl4 = random.randint(1,3)
                 if guess4 == tnl4:
                        print('You survived')
                        points = points + 50

                 elif guess4 != tnl4:
                        print("You found Cleo. Your damage has been increased but at a cost of some health")
                        health = health - 2
                        damage = damage + 1.4
                        points = points - 50
        #PART5
                        print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
                        guess5 = int(input("Make a guess"))
                        tnl5 = random.randint(1,3)
                        if guess5 == tnl5:
                             print('You survived')
                             print("You got 50 extra points!")
                             points = points + 100
                        elif guess5 != tnl5:
                               print("You encounter a demigorgon")
                               demigorgon1_health1 = 8
                               demigorgon1_damage = 2.5
                               demigorgon1_health2 = demigorgon1_health1 - damage
                               health = health - demigorgon1_damage
                               print("Your health is", health, "and the demigorgon's is", demigorgon1_health2)
                               demigorgon1_health3 = 0
                               health = health - demigorgon1_damage
                               print("The demigorgon is defearted but your health is", health)
                               points = points - 50
        #PART6
                               print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
                               guess6 = int(input("Make a guess"))
                               tnl6 = random.randint(1,3)
                               if guess6 == tnl6:
                                     print('You survived')
                                     points = points + 50
                                     print("These are your final points:", points," and this is your final health:", health)
                               elif guess6 != tnl6:
                                     print("You fell into a pool of acid. You lost health and extra points")
                                     health = health - 4
                                     points = points - 100
                                     print("These are your final points:", points," and this is your final health:", health)

I tried to make it so that different events would happen after choosing a tunnel, and after that you would move onto the next tunnel, but it didn’t work.

Asked By: DominionGaming

||

Answers:

Sticking to just the question; where you have "part2" you should dedent everything below that.

Its hard to know what sort of explanation will help you most but with something like this I like to think of index cards.

Every "If" creates two index cards. One for when it is true, one for when it is false.

You have one index card with:

print('You survived')
points = points + 50

And one card with everything else. The lightest pass fix would be something like:

#CAVEGAME
#Import
import random
import pickle
#Introduction
print("--------CaveGame V.4.1----------")
print("Credits - Rhys")
#Name loading
account_name = pickle.load(open( "caveuser1.pickle", "rb" ))
if account_name == 'Rhys':
 print("Welcome Rhys. Dev mode active")
elif account_name == 'Dev':
        print("Welcome developer. Dev mode active")
elif account_name == 'Mannat':
        print("You are not authorised to access this game.")
        quit()
elif account_name == 'Tammana':
 print("You are not authorised to access this game.")
 quit()
elif account_name == 'Yameen':
        print("You are not authorised to access this game - YAMEEN. ")
        quit()
elif account_name == 'CroissantMafia':
 print("Weclome Croissant Disciples. Go to this link for the code: https://github.com/DominionGaming/CaveGame")
else:
  print("Welcome to CaveGame")

#Stats
health = 20
damage = 1.5
points = 0
#PART1
print(account_name, "you are travelling down a cave and come to a fork in the cave. There are two paths - which do you choose?")
guess = int(input("Make a guess"))
tnl1 = random.randint(1,2)
if guess == tnl1:
        print('You survived')
        points = points + 50
elif guess != tnl1:
        print("You found a drakon")
        drakon1_health1 = 6
        drakon1_health2 = drakon1_health1 - damage
        drakon1_damage = 0.5
        health = health - drakon1_damage
        print("Your health is",health, "and the drakon's health is", drakon1_health2)
        health = health - drakon1_damage
        print("The drakon is defeated and your health is", health)
        points = points - 50
    
#PART2
print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. There are two paths - which do you choose?")
guess2 = int(input("Make a guess"))
tnl2 = random.randint(1,2)
if guess2 == tnl2:
    print('You survived')
    print("You recieved a combat upgrade. You now deal more damage")
    points = points + 50
    damage = damage + 2
elif guess2 != tnl2:
    print("A wave of fire rolls through the tunnel. You lose 5 health")
    health = health - 5
    points = points - 50

#PART3
print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
guess3 = int(input("Make a guess"))
tnl3 = random.randint(1,3)
if guess3 == tnl3:
    print('You survived')
    print("You recieved a health upgrade.")
    health = health + 1.4
    points = points + 50
elif guess3 != tnl3:
    print("There was a cave in. You lost")
    points = points - 50
    quit()

#PART4
print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
guess4 = int(input("Make a guess"))
tnl4 = random.randint(1,3)
if guess4 == tnl4:
    print('You survived')
    points = points + 50

elif guess4 != tnl4:
    print("You found Cleo. Your damage has been increased but at a cost of some health")
    health = health - 2
    damage = damage + 1.4
    points = points - 50

#PART5
print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
guess5 = int(input("Make a guess"))
tnl5 = random.randint(1,3)
if guess5 == tnl5:
    print('You survived')
    print("You got 50 extra points!")
    points = points + 100
elif guess5 != tnl5:
    print("You encounter a demigorgon")
    demigorgon1_health1 = 8
    demigorgon1_damage = 2.5
    demigorgon1_health2 = demigorgon1_health1 - damage
    health = health - demigorgon1_damage
    print("Your health is", health, "and the demigorgon's is", demigorgon1_health2)
    demigorgon1_health3 = 0
    health = health - demigorgon1_damage
    print("The demigorgon is defearted but your health is", health)
    points = points - 50

#PART6
print("Well", account_name, "you are travelling down a cave and come to another fork in the cave. This time there are three paths - which do you choose?")
guess6 = int(input("Make a guess"))
tnl6 = random.randint(1,3)
if guess6 == tnl6:
    print('You survived')
    points = points + 50
    print("These are your final points:", points," and this is your final health:", health)
elif guess6 != tnl6:
    print("You fell into a pool of acid. You lost health and extra points")
    health = health - 4
    points = points - 100
    print("These are your final points:", points," and this is your final health:", health)
Answered By: Jason Kane
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.