为什么我会收到这么多错误?

Why am I getting so many errors?

是的,我知道我的代码很乱,而且很糟糕,就像 20 行只是值为 0 的变量,我对 python 基本上一无所知,而且我已经超出了我的范围但是我需要一些关于点击播放(在 pycharm 上)时为什么会出现此错误的答案:文件“C:\Users\dank_\PycharmProjects\pythonProject\main.py”,第 184 行 elif atck1 == “飞镖”: ^ IndentationError:需要一个缩进块

我不明白...我还有一个红色警告,上面写着“预期缩进:48”,请有人解释一下,在此先感谢。

    import time
import random
FN = 0
Cha1 = 0
Cha2 = 0
Cha3 = 0
Cha4 = 0
SA1 = 0
cSA1 = 0
cSA2 = 0
cSA3 = 0
cSA4 = 0
cSA1a = 0
cSA2a = 0
cSA3a = 0
cSA4a = 0
character = 0
pl1 = 100
pl2 = 100
pl2a = 10
pl1a = 10
pl1w = 20
pl2w = 20
pl2f = 20
pl1f = 20
ph1 = 0
ph2 = 0
pd1 = 0
fd1 = 0
wd1 = 0
rd1 = 0
pd2 = 0
fd2 = 0
wd2 = 0
rd2 = 0
DPH = 0
DPH1 = 0
DPH2 = 0
DPH3 = 0
DPH4 = 0
HA = 70

tcharacter = ""
tcharacter2 = ""
while FN == 0:
    sad = input("Roll the dice!: ")
    if sad != "no":
    FN = + 1
    if sad == "no":
       JJJ = random.randint(1, 4)
       if JJJ == 1:
           print("Come on, just do it. ")
       elif JJJ == 2:
           print("Really? come on")
       elif JJJ == 3:
           print("I said roll the dice")

char1 = random.randint(1, 4)

if char1 == 1:
    print("You pulled...")
    time.sleep(0.1)
    print("The Danger Ranger")
    Cha1 = + 1
    cSA1 = + 1
elif char1 == 2:
    print("You pulled...")
    time.sleep(0.1)
    print("Fire Flame Man")
    Cha2 = + 1
    cSA2 = + 1
elif char1 == 3:
    print("You pulled...")
    time.sleep(0.1)
    print("Water Winkle Wanderer")
    Cha3 = + 1
    cSA3 = + 1
elif char1 == 4:
    print("You pulled...")
    time.sleep(0.1)
    print("Poisoned Platter Person")
    Cha4 = + 1
    cSA4 = + 1
ph1 = + 1






while SA1 == 0:
   SA1 = input("Roll the dice!: ")
   if SA1 != "no":
    SA1 =+ 1
   if SA1 == "no":
       JJJ = random.randint(1, 4)
       if JJJ == 1:
           print("Come on, just do it. ")
       elif JJJ == 2:
           print("Really? come on")
       elif JJJ == 3:
           print("I said roll the dice")

char2 = random.randint(1, 4)

if char2 == 1:
    if Cha1 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("The Danger Ranger")
        Cha1 = + 1
        cSA1a = + 1
elif char2 == 2:
    if Cha2 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Fire Flame Man")
        Cha2 = + 1
        cSA2a = + 1
elif char2 == 3:
    if Cha3 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Water Winkle Wanderer")
        Cha3 = + 1
        cSA3a = + 1
elif char2 == 4:
    if Cha4 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Poisoned Platter Person")
        Cha4 = + 1
        cSA4a = + 1
ph2 = + 1

if cSA1 == 1:
    tcharacter = "The Danger Ranger"
elif cSA2 == 1:
    tcharacter = "Fire Flame Man"
elif cSA3 == 1:
    tcharacter = "Water Winkle Wanderer"
elif cSA4 == 1:
    tcharacter = "Poisoned Platter Person"

print("Player 1, your character is", tcharacter, "Your attacks are...")
time.sleep(1)

if tcharacter == "The Danger Ranger":
    print("Six shooter, 6 quick shots of random damage, to use, say \"Six\"... Oversized Hat, 1 Slow attack based on your health, to use, say \"Hat\"... Lever action, 1 quick high damage attack, to use, say \"Bang\"")
elif tcharacter == "Fire Flame Man":
    print("Fireball, 1 quick attack on random damage, to use, say \"Fire\"... Oxygen, adds damage to your next attack and increases defense, to use, say \"Oxy\"... Falling Debris, 10 quick attacks on random damage, to use, say \"Fall\"")
elif tcharacter == "Water Winkle Wanderer":
    print("Tsunami, 1 massive slow attack, to use, say \"Wave\"... Flash Flood, 1 Instant low damage attack, to use, say \"Flood\" ")
elif tcharacter == "Poisoned Platter Person":
    print("Spoiled Bread, 1 Instant high damage attack, high chance to miss, to use, say \"Bread\"... Poisoned Dart, 1 quick medium damage attack, to use, say \"Dart\"... Tainted Wine, 1 Instant no damage attack, lowers your opponents defens permanantly, to use, say \"Wine\" ")


if cSA1a == 1:
    tcharacter2 = "The Danger Ranger"
elif cSA2a == 1:
    tcharacter2 = "Fire Flame Man"
elif cSA3a == 1:
    tcharacter2 = "Water Winkle Wanderer"
elif cSA4a == 1:
    tcharacter2 = "Poisoned Platter Person"

print("Player 2, your character is", tcharacter2, "Your attacks are...")

if tcharacter2 == "The Danger Ranger":
    print("Six shooter, 6 quick shots of random damage, to use, say \"Six\"... Oversized Hat, 1 Slow attack based on your health, to use, say \"Hat\"... Lever action, 1 quick high damage attack, to use, say \"Bang\"")
elif tcharacter2 == "Fire Flame Man":
    print("Fireball, 1 quick attack on random damage, to use, say \"Fire\"... Oxygen, adds damage to your next attack and increases defense, to use, say \"Oxy\"... Falling Debris, 10 quick attacks on random damage, to use, say \"Fall\"")
elif tcharacter2 == "Water Winkle Wanderer":
    print("Tsunami, 1 massive slow attack, to use, say \"Wave\"... Flash Flood, 1 Instant low damage attack, to use, say \"Flood\" ")
elif tcharacter2 == "Poisoned Platter Person":
    print("Spoiled Bread, 1 Instant high damage attack, high chance to miss, to use, say \"Bread\"... Poisoned Dart, 1 quick medium damage attack, to use, say \"Dart\"... Tainted Wine, 1 Instant no damage attack, lowers your opponents defense permanantly, to use, say \"Wine\" ")


atck1 = input("What attack do you use Player 1?")

if pd1 >= 1:
    if atck1 == "Bread":
        PA1 = random.randint(0, 8)
        HA = + PA1
        JL1 = random.randint(1, 3)
        if JL1 == 1:
            pl2 = - PA1
            print("Hit! Player 2 is now at", pl2, "health")
            if PA1 >= 5:
                print("Critical Hit!")
        else:
            pl1a = - 10
            print("Miss!")

elif atck1 == "Wine":
            PA2 = random.randint(1, 6)
            if PA2 == 1:
                pl1a = - 10
                print("Miss!")
            else:
                pl2a = - 15
                print("Hit! Opponent's defense now at", pl2a)

elif atck1 == "Dart":
        PA3 = random.randint(1, 10)
        if PA3 == 1:
              pl1a = - 10
              pl1 = - 1
              print("Ouch! You accidentally poked yourself with the dart! ")

        else:
            H1 = 10
            pl2a = + DPH
            DPH /= 4
            DPH = - H1
            H1 = - pl2
            print("Hit!")

elif wd1 >= 1:
    if atck1 == "Wave":
        H2 = random.randint(0, 7)
        JL2 = random.randint(1, 5)
        if JL2 == 1:
            H3 = 70
            pl2a = + DPH1
            DPH1 /= 4
            DPH1 = - H3
            H3 = - pl2
            print("Hit! Player 2 is now at", pl2, "health")
            if H2 >= 5:
                print("Critical Hit!")
        else:
            pl1a =- 10
            print("Miss!")

    elif atck1 == "Flood":
        H4 = 14
        pl2a = + DPH2
        DPH2 /= 4
        DPH2 = - H4
        H1 = - pl2
        pl2 = - H4
        print("Oof, Player 2 is now at", pl2, "health" )

elif fd1 >= 1:
    print("testpls")

elif rd1 >= 1:
    print("a")

第 1 行的额外缩进

    import time
import random

第 48 行缺少缩进

while FN == 0:
sad = input("Roll the dice!: ")
if sad != "no":
FN = + 1 #here should have indent
if sad == "no":
   JJJ = random.randint(1, 4)
   if JJJ == 1:
       print("Come on, just do it. ")
   elif JJJ == 2:
       print("Really? come on")
   elif JJJ == 3:
       print("I said roll the dice")

我在第 48 行修复了你的缩进问题。

import time
import random
FN = 0
Cha1 = 0
Cha2 = 0
Cha3 = 0
Cha4 = 0
SA1 = 0
cSA1 = 0
cSA2 = 0
cSA3 = 0
cSA4 = 0
cSA1a = 0
cSA2a = 0
cSA3a = 0
cSA4a = 0
character = 0
pl1 = 100
pl2 = 100
pl2a = 10
pl1a = 10
pl1w = 20
pl2w = 20
pl2f = 20
pl1f = 20
ph1 = 0
ph2 = 0
pd1 = 0
fd1 = 0
wd1 = 0
rd1 = 0
pd2 = 0
fd2 = 0
wd2 = 0
rd2 = 0
DPH = 0
DPH1 = 0
DPH2 = 0
DPH3 = 0
DPH4 = 0
HA = 70

tcharacter = ""
tcharacter2 = ""
while FN == 0:
    sad = input("Roll the dice!: ")
    if sad != "no":
        FN = + 1
    if sad == "no":
       JJJ = random.randint(1, 4)
       if JJJ == 1:
           print("Come on, just do it. ")
       elif JJJ == 2:
           print("Really? come on")
       elif JJJ == 3:
           print("I said roll the dice")

char1 = random.randint(1, 4)

if char1 == 1:
    print("You pulled...")
    time.sleep(0.1)
    print("The Danger Ranger")
    Cha1 = + 1
    cSA1 = + 1
elif char1 == 2:
    print("You pulled...")
    time.sleep(0.1)
    print("Fire Flame Man")
    Cha2 = + 1
    cSA2 = + 1
elif char1 == 3:
    print("You pulled...")
    time.sleep(0.1)
    print("Water Winkle Wanderer")
    Cha3 = + 1
    cSA3 = + 1
elif char1 == 4:
    print("You pulled...")
    time.sleep(0.1)
    print("Poisoned Platter Person")
    Cha4 = + 1
    cSA4 = + 1
ph1 = + 1






while SA1 == 0:
   SA1 = input("Roll the dice!: ")
   if SA1 != "no":
    SA1 =+ 1
   if SA1 == "no":
       JJJ = random.randint(1, 4)
       if JJJ == 1:
           print("Come on, just do it. ")
       elif JJJ == 2:
           print("Really? come on")
       elif JJJ == 3:
           print("I said roll the dice")

char2 = random.randint(1, 4)

if char2 == 1:
    if Cha1 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("The Danger Ranger")
        Cha1 = + 1
        cSA1a = + 1
elif char2 == 2:
    if Cha2 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Fire Flame Man")
        Cha2 = + 1
        cSA2a = + 1
elif char2 == 3:
    if Cha3 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Water Winkle Wanderer")
        Cha3 = + 1
        cSA3a = + 1
elif char2 == 4:
    if Cha4 < 1:
        print("You pulled...")
        time.sleep(0.1)
        print("Poisoned Platter Person")
        Cha4 = + 1
        cSA4a = + 1
ph2 = + 1

if cSA1 == 1:
    tcharacter = "The Danger Ranger"
elif cSA2 == 1:
    tcharacter = "Fire Flame Man"
elif cSA3 == 1:
    tcharacter = "Water Winkle Wanderer"
elif cSA4 == 1:
    tcharacter = "Poisoned Platter Person"

print("Player 1, your character is", tcharacter, "Your attacks are...")
time.sleep(1)

if tcharacter == "The Danger Ranger":
    print("Six shooter, 6 quick shots of random damage, to use, say \"Six\"... Oversized Hat, 1 Slow attack based on your health, to use, say \"Hat\"... Lever action, 1 quick high damage attack, to use, say \"Bang\"")
elif tcharacter == "Fire Flame Man":
    print("Fireball, 1 quick attack on random damage, to use, say \"Fire\"... Oxygen, adds damage to your next attack and increases defense, to use, say \"Oxy\"... Falling Debris, 10 quick attacks on random damage, to use, say \"Fall\"")
elif tcharacter == "Water Winkle Wanderer":
    print("Tsunami, 1 massive slow attack, to use, say \"Wave\"... Flash Flood, 1 Instant low damage attack, to use, say \"Flood\" ")
elif tcharacter == "Poisoned Platter Person":
    print("Spoiled Bread, 1 Instant high damage attack, high chance to miss, to use, say \"Bread\"... Poisoned Dart, 1 quick medium damage attack, to use, say \"Dart\"... Tainted Wine, 1 Instant no damage attack, lowers your opponents defens permanantly, to use, say \"Wine\" ")


if cSA1a == 1:
    tcharacter2 = "The Danger Ranger"
elif cSA2a == 1:
    tcharacter2 = "Fire Flame Man"
elif cSA3a == 1:
    tcharacter2 = "Water Winkle Wanderer"
elif cSA4a == 1:
    tcharacter2 = "Poisoned Platter Person"

print("Player 2, your character is", tcharacter2, "Your attacks are...")

if tcharacter2 == "The Danger Ranger":
    print("Six shooter, 6 quick shots of random damage, to use, say \"Six\"... Oversized Hat, 1 Slow attack based on your health, to use, say \"Hat\"... Lever action, 1 quick high damage attack, to use, say \"Bang\"")
elif tcharacter2 == "Fire Flame Man":
    print("Fireball, 1 quick attack on random damage, to use, say \"Fire\"... Oxygen, adds damage to your next attack and increases defense, to use, say \"Oxy\"... Falling Debris, 10 quick attacks on random damage, to use, say \"Fall\"")
elif tcharacter2 == "Water Winkle Wanderer":
    print("Tsunami, 1 massive slow attack, to use, say \"Wave\"... Flash Flood, 1 Instant low damage attack, to use, say \"Flood\" ")
elif tcharacter2 == "Poisoned Platter Person":
    print("Spoiled Bread, 1 Instant high damage attack, high chance to miss, to use, say \"Bread\"... Poisoned Dart, 1 quick medium damage attack, to use, say \"Dart\"... Tainted Wine, 1 Instant no damage attack, lowers your opponents defense permanantly, to use, say \"Wine\" ")


atck1 = input("What attack do you use Player 1?")

if pd1 >= 1:
    if atck1 == "Bread":
        PA1 = random.randint(0, 8)
        HA = + PA1
        JL1 = random.randint(1, 3)
        if JL1 == 1:
            pl2 = - PA1
            print("Hit! Player 2 is now at", pl2, "health")
            if PA1 >= 5:
                print("Critical Hit!")
        else:
            pl1a = - 10
            print("Miss!")

elif atck1 == "Wine":
            PA2 = random.randint(1, 6)
            if PA2 == 1:
                pl1a = - 10
                print("Miss!")
            else:
                pl2a = - 15
                print("Hit! Opponent's defense now at", pl2a)

elif atck1 == "Dart":
        PA3 = random.randint(1, 10)
        if PA3 == 1:
              pl1a = - 10
              pl1 = - 1
              print("Ouch! You accidentally poked yourself with the dart! ")

        else:
            H1 = 10
            pl2a = + DPH
            DPH /= 4
            DPH = - H1
            H1 = - pl2
            print("Hit!")

elif wd1 >= 1:
    if atck1 == "Wave":
        H2 = random.randint(0, 7)
        JL2 = random.randint(1, 5)
        if JL2 == 1:
            H3 = 70
            pl2a = + DPH1
            DPH1 /= 4
            DPH1 = - H3
            H3 = - pl2
            print("Hit! Player 2 is now at", pl2, "health")
            if H2 >= 5:
                print("Critical Hit!")
        else:
            pl1a =- 10
            print("Miss!")

    elif atck1 == "Flood":
        H4 = 14
        pl2a = + DPH2
        DPH2 /= 4
        DPH2 = - H4
        H1 = - pl2
        pl2 = - H4
        print("Oof, Player 2 is now at", pl2, "health" )

elif fd1 >= 1:
    print("testpls")

elif rd1 >= 1:
    print("a")