E901,或TokenError:repl.it

时间:2017-08-14 19:58:18

标签: python-3.x

我一直在名为https://repl.it的网站上编码。 PEP8在最后一行返回错误:

E901, or TokenError: EOF in multi-line statement`.

我尝试重写该部分,重做缩进,并重命名变量。

CNC中 我已经检查了缩进和if语句,所以这里是新代码。它仍然提出同样的问题。请注意,我对代码不是很擅长并且可能无法理解你对蝙蝠的意思。我还会尝试在代码中添加注释。

from random import randint
from time import sleep
advList = ["Crawl", "Walk", "Run", "Sprint"]
atkList = ["[A] Punch", "[B] Kick", "[C] Magic"]
restart = 1
myHp = 50
zomHp = 50
battle = 50

#Game Over Screen
if myHp <= 0:
    print("YOU DIED")
    print("GAME OVER")
    quit()

#Endless Game Function
for i in range(0, reset):

    #Traveling Loop
    while battle > 5:
        print(advList)
        trv = str(input("How would you like to advance?"))

        if trv == advList[0]:
            sleep(8)
            myHp = myHp + 10
            battle = randint(0, 40)
        if trv == advList[1]:
            sleep(4)
            myHp = myHp + 5
            battle = randint(0, 30)
        if trv == advList[2]:
            sleep(2)
            myHp = myHp + 2
            battle = randint(0, 20)

        if trv == advList[3]:
            sleep(1)
            myHp = myHp + 1
            battle = randint(0, 10)

#Max Health Cap
        if myHp >= 50:
            myHp = 50
        print("My Hp: ", myHp)
        print('')


#Battle Sequence
    if battle <= 5:
        print ("A zombie  approaches!!!")
        sleep(1)
        while battle <= 5:
            print (atkList)
            atk = str(input("How do you attack?"))
            #Randomizes Hit Chance
            khit = randint(0, 2)
            phit = randint(0, 1)
            mhit = randint(0, 5)
            zhit = randint(0, 4)
#Kick Attack
            if atk == "B":
                dmg = randint(1, 25)
                if khit != 1:
                    print ("Your Attack Missed...")

                if khit == 1:
                    zomHp = zomHp - dmg
                    print (("The Attack Hits for %s damage") %(dmg))
#Punch Attack
            if atk == "A":
                dmg = randint(1, 10)
                if phit == 0:
                    print ("Your Attack Missed...")

                if phit == 1:
                    zomHp = zomHp - dmg
                    print (("The Attack Hits for %s damage") %(dmg))
#Magic Attack
            if atk == "C":
                dmg = randint(1, 50)
                if mhit != 0:
                    print ("Your Attack Missed...")

                if mhit == 0:
                    zomHp = zomHp - dmg
                    print (("The Attack Hits for %s damage") %(dmg)
#Zombie's Hit
            if zhit == 0:
                zdmg = randint(1, 10)
                myHp = myHp - zdmg
                print (("The Zombie's attack Hits for %s damage")(zdmg))
                print ("My Hp:", myHp)
#Zombie Miss
            if zhit != 0:
            print ("My Hp:", myHp)
#Zombie Dies
            if zomHp <= 0:
                print ("You defeated the Zombie!!!")
                battle = 50
#Round End
    print("Zombie's HP:", zomHp)
    print('')

1 个答案:

答案 0 :(得分:0)

我收到错误

File "<ipython-input-3-252d942b8c20>", line 82
if zhit == 0:
            ^
SyntaxError: invalid syntax

所以,我注意到&#34; zhit&#34;不应该初始化为零,因为这与比较运算符冲突。其次,如果您可以在代码中添加注释以了解游戏的目的,将会很有帮助。至于pep8上的EOF错误,pep8的文档可能有用,EOF901指向E901 SyntaxError或IndentationError。在Python中,适当的缩进是最重要的。我希望这有助于http://pep8.readthedocs.io/en/release-1.7.x/intro.html

将此代码复制到文本编辑器(如Sublime,Atom或Visual Studio)并切换到调试模式以逐行执行代码也是一个好主意。我尝试了Jupyter笔记本上的代码,并没有找到这个错误,虽然不同。 https://repl.it/languages/python3站点也有自己的调试环境。也许,这将有助于您确定此错误的来源。