所以我正在做我的GSCE,我们的任务是创建一个简单的基于文本的游戏。我试图添加一些数据验证来向我的老师展示我可以做到,但是事实证明……我做不到……对于那些精通Python的人来说,似乎有些容易,但是由于某种原因当我运行程序时,它具有“无效语法”,因此我解决了该问题(只需添加“:”),但随后它说缩进是错误的吗?数据验证接近开始,您可以选择“向左”或“向右”。如果您键入“ left”或“ right”以外的其他内容,我希望它再次给您一个问题。请有人帮助! (也请忽略垃圾的故事)。

import time
import sys

print("Mars: 2040. The human race has been wiped out of existence by the alien race. Will you suffer the same fate?")
time.sleep(3)
name=input("What is your name?")

def start()
    print("Okay",name,", which direction would you like to go? Left or right?")
    direction=input()

    if direction == "left":
        print("You turn the corner to discover a large, wolf-life monster. It erupts in deafening roar and proceeds towards you.")
            print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
            weapon=input()

            if weapon == "bow":
                print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
                print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
                weapon2=input()

                if weapon2 == "shoot again":
                      print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
                      time.sleep(3)
                      print("GAME OVER")
                      exit()

                if weapon2 == "reach for your pocket":
                        print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
                        time.sleep(4)
                        print("Congratulations! You win!!1! :D")
                        print("Game created by Tom Jolley.")

            elif weapon == "sword":
                print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
                time.sleep(5)
                print("GAME OVER")
                exit()

    elif direction == "right":
            print("You turn the corner to discover a ginormous arachnid drooling and staring at you with it's 8 glowing red eyes. It proceeds towards you.")
            print("...well no, that's not a direction... just stand there..")
            print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
            weapon=input()

            if weapon == "bow":
                print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
                print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
                weapon2=input()

                if weapon2 == "shoot again":
                      print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
                      time.sleep(3)
                      print("GAME OVER")
                      exit()

                if weapon2 == "reach for your pocket":
                        print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
                        time.sleep(4)
                        print("Congratulations! You win!!1! :D")
                        print("Game created by Tom Jolley.")

            elif weapon == "sword":
                print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
                time.sleep(5)
                print("GAME OVER")
                exit()


    else:
        print()
        start()

start()

最佳答案

这里主要是间距问题,有很多8个空格而不是4个,有些地方是5个

import time
import sys

print("Mars: 2040. The human race has been wiped out of existence by the alien race. Will you suffer the same fate?")
time.sleep(3)
name=input("What is your name?")

def start()
    print("Okay",name,", which direction would you like to go? Left or right?")
    direction=input()

    if direction == "left":
        print("You turn the corner to discover a large, wolf-life monster. It erupts in deafening roar and proceeds towards you.")
        print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
        weapon=input()

        if weapon == "bow":
            print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
            print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
                weapon2=input()

            if weapon2 == "shoot again":
                 print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
                 time.sleep(3)
                 print("GAME OVER")
                 exit()

            if weapon2 == "reach for your pocket":
                print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
                time.sleep(4)
                print("Congratulations! You win!!1! :D")
                print("Game created by Tom Jolley.")

        elif weapon == "sword":
            print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
            time.sleep(5)
            print("GAME OVER")
            exit()

    elif direction == "right":
        print("You turn the corner to discover a ginormous arachnid drooling and staring at you with it's 8 glowing red eyes. It proceeds towards you.")
        print("...well no, that's not a direction... just stand there..")
        print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
        weapon=input()

        if weapon == "bow":
            print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
            print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
            weapon2=input()

            if weapon2 == "shoot again":
                print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
                time.sleep(3)
                print("GAME OVER")
                exit()

            if weapon2 == "reach for your pocket":
                print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
                time.sleep(4)
                print("Congratulations! You win!!1! :D")
                print("Game created by Tom Jolley.")

        elif weapon == "sword":
            print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
            time.sleep(5)
            print("GAME OVER")
            exit()


    else:
        print()
        start()

start()

10-06 06:23