Python Unindent不匹配任何外部缩进级别错误

Python Unindent不匹配任何外部缩进级别错误,python,pygame,Python,Pygame,我正在尝试创建一个游戏,但我不断收到一个错误“Unindent不匹配任何外部缩进级别”,使我的代码无法运行 我试着改变顺序,寻找错误,但没有发现任何错误 导入pygame,sys 从pygame.locals导入* #Initialize Package pygame.init() win = pygame.display.set_mode ((640,600)) pygame.display.set_caption("EduCAUTION") #Colours init crushed =

我正在尝试创建一个游戏,但我不断收到一个错误“Unindent不匹配任何外部缩进级别”,使我的代码无法运行

我试着改变顺序,寻找错误,但没有发现任何错误

导入pygame,sys 从pygame.locals导入*

#Initialize Package
pygame.init()
win = pygame.display.set_mode ((640,600))
pygame.display.set_caption("EduCAUTION")

#Colours init
crushed = (142, 71, 71)
white = (250, 250, 250)

#Text init
pygame.font.init()
myfont = pygame.font.SysFont('Arial', 50)
subtitle = pygame.font.SysFont('Arial', 25)
normal = pygame.font.SysFont('comicsans', 20)

#Hardware Game Text
hardtitle = myfont.render('Beware Hardware', False, (crushed))
hardrules = subtitle.render('Walk the character to the right answer to clear the path.', False, (75,75,75))
hardQ1 = myfont.render('RAM stands for...', False, (crushed))
Hopt1 = subtitle.render('Random Access Memory', False, (75,75,75))
Hopt2 = subtitle.render('Rotten Apple Monkey', False, (75,75,75))

#Images Init
hardBG = pygame.image.load('comsciBG.jpg')
#Animation
walkRight = [pygame.image.load('R1.png'), pygame.image.load('R2.png'), pygame.image.load('R3.png'), pygame.image.load('R4.png'), pygame.image.load('R5.png'), pygame.image.load('R6.png'), pygame.image.load('R7.png'), pygame.image.load('R8.png'), pygame.image.load('R9.png')]
walkLeft = [pygame.image.load('L1.png'), pygame.image.load('L2.png'), pygame.image.load('L3.png'), pygame.image.load('L4.png'), pygame.image.load('L5.png'), pygame.image.load('L6.png'), pygame.image.load('L7.png'), pygame.image.load('L8.png'), pygame.image.load('L9.png')]
left = False
right = False
walkCount = 0
#Constants
x = 60
y = 300
width = 50
height = 50
vel = 25
end = 540

#Variables
game3 = 0

def comSci():
    global game3
    global walkCount
    if walkCount + 1 >= 27:
        walkCount = 0
    win.blit(hardBG, (-5,-20))
    win.blit(hardtitle, (160, 15))
    win.blit(hardrules, (60,80))
    if game3 == 0:
        win.blit(hardQ1, (200, 200))
        pygame.draw.rect(win, white,(15,290,250,50))
        pygame.draw.rect(win, white,(405, 290, 220, 50))
        win.blit(Hopt1, (30, 300))
        win.blit(Hopt2, (420, 300))
    # If facing left
    if left:
        gameWindow.blit(walkLeft[walkCount//3], (x,y))  
        walkCount += 1
    # If facing right
    if right: 
        gameWindow.blit(walkRight[walkCount//3], (x,y))
        walkCount += 1

    pygame.display.update()

run = True
while run:
    #Quit game
    pygame.time.delay(100)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

     if keys[pygame.K_LEFT] and x > 15:
        x -= vel
        left = True
        right = False

    elif keys[pygame.K_RIGHT] and x < 590 - vel - width:  
        x += vel
        left = False
        right = True

    elif keys[pygame.K_UP]  :
        if x >= 200 and y>=40:
            y -= vel
            left = False
             right = False

    elif keys[pygame.K_DOWN] and y < 404 - vel - width:
        y += vel
        left = False
        right = False

    else: 
        left = False
        right = False
        walkCount = 0
    comSci()

#End Game
pygame.quit()
#初始化包
pygame.init()
win=pygame.display.set_模式((640600))
pygame.display.set_标题(“教育警告”)
#颜色初始化
压碎=(142、71、71)
白色=(250250250)
#文本初始化
pygame.font.init()
myfont=pygame.font.SysFont('Arial',50)
subtitle=pygame.font.SysFont('Arial',25)
normal=pygame.font.SysFont('comicsans',20)
#硬件游戏文本
hardttitle=myfont.render('小心硬件',False,(压碎))
hardrules=subtitle.render('将角色移动到正确答案以清除路径',False,(75,75,75))
hardQ1=myfont.render('RAM代表…',False,(压碎))
Hopt1=subtitle.render('Random Access Memory',False,(75,75,75))
Hopt2=subtitle.render('烂苹果猴',假,(75,75,75))
#图像初始化
hardBG=pygame.image.load('comsciBG.jpg')
#动画
walkRight=[pygame.image.load('R1.png')、pygame.image.load('R2.png')、pygame.image.load('R3.png')、pygame.image.load('R4.png')、pygame.image.load('R5.png')、pygame.image.load('R6.png')、pygame.image.load('R7.png')、pygame.image.load('R8.png')、pygame.image.load('R9.png')]
walkLeft=[pygame.image.load('L1.png')、pygame.image.load('L2.png')、pygame.image.load('L3.png')、pygame.image.load('L4.png')、pygame.image.load('L6.png')、pygame.image.load('L7.png')、pygame.image.load('L8.png')、pygame.image.load('L9.png')]
左=假
右=假
步行次数=0
#常数
x=60
y=300
宽度=50
高度=50
水平=25
结束=540
#变数
游戏3=0
def comSci():
全球游戏3
全局步行计数
如果walkCount+1>=27:
步行次数=0
win.blit(硬BG,(-5,-20))
博利特(硬标题,(160,15))
win.blit(硬规则(60,80))
如果game3==0:
win.blit(hardQ1,(200200))
pygame.draw.rect(赢,白,(15290250,50))
pygame.draw.rect(赢,白,(405290220,50))
win.blit(Hopt1,(30,300))
win.blit(Hopt2,(420300))
#如果朝左
如果留下:
blit(walkLeft[walkCount//3],(x,y))
步行次数+=1
#如果面朝右
如果正确:
blit(walkRight[walkCount//3],(x,y))
步行次数+=1
pygame.display.update()
运行=真
运行时:
#退出游戏
pygame.时间延迟(100)
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
运行=错误
如果键[pygame.K_LEFT]和x>15:
x-=水平
左=真
右=假
elif键[pygame.K_RIGHT]和x<590-水平-宽度:
x+=vel
左=假
右=真
elif keys[pygame.K_UP]:
如果x>=200且y>=40:
y-=水平
左=假
右=假
elif键[pygame.K_DOWN]和y<404-水平-宽度:
y+=水平
左=假
右=假
其他:
左=假
右=假
步行次数=0
comSci()
#终局
pygame.quit()

假定该代码允许基于鼠标单击移动动画。(是的,我知道变量有点不准确,这是一项正在进行的工作)。如何修复此错误?

不确定这是否能解决此问题,但此处的if:

如果键[pygame.K_左]和x>15:
x-=水平
左=真
右=假

如果
比缩进块的其余部分领先一个空格,这可能是使用Python3的原因。+

你没做什么,python在计算缩进方面遇到了问题,要解决它,突出显示你的所有工作,请在页面顶部使用类似“文件编辑格式”的内容单击format,然后单击tabify region并按ok

当出现语法错误时,Python会给出错误所在的行。请提供这个。这对你有帮助吗?