Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复基于文本的冒险游戏中的缩进错误_Python_Python 2.7_Random_Adventure - Fatal编程技术网

Python 如何修复基于文本的冒险游戏中的缩进错误

Python 如何修复基于文本的冒险游戏中的缩进错误,python,python-2.7,random,adventure,Python,Python 2.7,Random,Adventure,我正在做一个基于文本的冒险游戏,但是我试着运行我的程序的一部分,在有我无法修复的astricks的行中有一个缩进错误。有人能给我一些指点吗。谢谢我们将非常感谢您的帮助 以下是我的部分代码: import random import time randint = random.randint(1, 9) randint2 = random.randint(1, 8) randint3 = random.randint(1, 7) randint4 = rando

我正在做一个基于文本的冒险游戏,但是我试着运行我的程序的一部分,在有我无法修复的astricks的行中有一个缩进错误。有人能给我一些指点吗。谢谢我们将非常感谢您的帮助

以下是我的部分代码:

   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')

因此,强烈建议使用“TAB”标识代码,以避免这些错误,因此,如果您的“if”语句中有任何内容,则应该使用一个TAB和一个TAB。始终使用选项卡来识别。基于此,这里就是了

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')
    

哪个“if”是“else:”应该对应的?如果L_1==“卧房”,则在下方需要一个缩进块:。如果你有
#插入卧室代码
,你需要一些代码。另外
打印(通过)
是无效语法。如果你不使用have one-space缩进块,你会发现正确缩进代码更容易。我留下了一个打印(通过)以便稍后再回来