How do i fix an indention error in my text based adventure game

49 views Asked by At

I am making a text-based adventure game, however i tried running part of my program and there is an indentation error in line where there are astricks in which i cannot fix. Could someone give me some pointers. Thanks! All help will be well appreciated

Here is apart of my code:

   import random
   import time
   randint = random.randint(1, 9)
   randint2 = random.randint(1, 8)
   randint3 = random.randint(1, 7)
   randint4 = random.randint(1, 3)
   person_name = input('What is your name? ')
   print('your name is: ',person_name)
   print('you have been trapped in a haunted house....You have to hurry and                            escape this house')
   time.sleep(0.9)
   roomchoice_1 = input('You are currently located in the living room.                 Would you like to walk to the Kitchen, bedroom, or the basement?: ')
   time.sleep(1.32)

   if roomchoice_1 == 'Kitchen':
    print('okay you are now in the kitchen, now solve the combination lock.   It will help you get out of here!')
    time.sleep(1.5)
    print('You have three guesses, if you get all three  wrong......well....you,ll die. Good Luck!')
    time.sleep(1.5)
    num1 = int(input('enter your first number, from 1 - 9'))
    print(' the correct number is: ' + randint)
    if num1 == randint:
     print('correct! You may now move on')
    else:
     print('oops, that wasnt the correct number. Try again. You now have 2  tries remaining')
     num2 = int(input('Choose your second number, from 1 - 8'))
     if num2 == randint2:
        print('Congrats you have successfully found the code')
     else:
        print('uhhh....that wasnt the correct number either...try again.')
        num3 = int(input('choose your third and final number between 1 and 7'))
        print('the correct number is', randint3)
        if num3 == randint3:
            print('well done ,success, you have opened the combination lock... You have obtained a key')
            L_1 = input(' Now would you like to travel to the bedroom or basement')
            if L_1 == 'Bedroom':
                            #insert bedroom code
        ***else:***
            print('Oh NO!, you have guessed incorrectly three times....')
            print(pass)# insert in print statement a code photo of a hole
            print(person_name, ' has died')
            print(pass)# insert text image of skull
   if roomchoice_1 == 'bedroom':
    print('You have walked into the bedroom.....')
    time.sleep(1)
    print('LOOK... there are three doors... You have to choose the correct  one...carefull! You only have one chance')
    choice_door = int(input('Choose one of the following doors: Door 1, Door 2, or Door 3'))
    if choice_door = randint4:
     print('Good Job... You have chosen the right door....')
     time.sleep(1)
     print('look behind the door... there is a chest...try open it...')
     open_chest = input('Would you like to open the chest')
     if open_chest == 'yes':
        print('Look... there is another key... this might be the key that opens the from')
1

There are 1 answers

0
IcaroSalgado On BEST ANSWER

So it is highly recommended to ident your code with 'TAB' to avoid those mistakes, so if you have any thing inside you 'if' statement it should be with one TAB and so one. Always use the TAB to ident. So based on that, here it is.

import random
import time


randint = random.randint(1, 9)
randint2 = random.randint(1, 8)
randint3 = random.randint(1, 7)
randint4 = random.randint(1, 3)
person_name = input('What is your name? ')
print('your name is: ',person_name)
print('you have been trapped in a haunted house....You have to hurry and                            escape this house')
time.sleep(0.9)
roomchoice_1 = input('You are currently located in the living room.                 Would you like to walk to the Kitchen, bedroom, or the basement?: ')
time.sleep(1.32)

if roomchoice_1 == 'Kitchen':
    print('okay you are now in the kitchen, now solve the combination lock.   It will help you get out of here!')
    time.sleep(1.5)
    print('You have three guesses, if you get all three  wrong......well....you,ll die. Good Luck!')
    time.sleep(1.5)
    num1 = int(input('enter your first number, from 1 - 9'))
    print(' the correct number is: ' + randint)
if num1 == randint:
    print('correct! You may now move on')
else:
    print('oops, that wasnt the correct number. Try again. You now have 2  tries remaining')
    num2 = int(input('Choose your second number, from 1 - 8'))
    if num2 == randint2:
        print('Congrats you have successfully found the code')
    else:
        print('uhhh....that wasnt the correct number either...try again.')
        num3 = int(input('choose your third and final number between 1 and 7'))
        print('the correct number is', randint3)
    if (num3 == randint3):
        print('well done ,success, you have opened the combination lock... You have obtained a key')
        L_1 = input(' Now would you like to travel to the bedroom or basement')
        if (L_1 == 'Bedroom'):
            pass             #insert bedroom code
        else:
            print('Oh NO!, you have guessed incorrectly three times....')
            #print(pass) # insert in print statement a code photo of a hole
            print(person_name, ' has died')
            #print(pass)# insert text image of skull

if roomchoice_1 == 'bedroom':
    print('You have walked into the bedroom.....')
    time.sleep(1)
    print('LOOK... there are three doors... You have to choose the correct  one...carefull! You only have one chance')
    choice_door = int(input('Choose one of the following doors: Door 1, Door 2, or Door 3'))
    if choice_door == randint4:
        print('Good Job... You have chosen the right door....')
        time.sleep(1)
        print('look behind the door... there is a chest...try open it...')
        open_chest = input('Would you like to open the chest')
        if open_chest == 'yes':
            print('Look... there is another key... this might be the key that opens the from')