我一直得到21行错误'在Python中

时间:2015-12-03 15:56:50

标签: python syntax-error

嗯,我遇到过这个网站,我遇到了一个需要回答的问题。我有一个起始游戏代码(由Python' Turtle创建)。我一直在第21行遇到语法错误。如果我更改该行上的代码并不重要,它会不断弹出。希望你们能帮忙。

import turtle
import time

wn = turtle.Screen()
wn.bgcolor('black')
startingTurtle = turtle.Turtle()
backHigh = turtle.Turtle()

score=0
lives=3
entrance_time=5

while entrance_time == 5:
  entrance = turtle.Turtle()
  entrance.hideturtle()
  entrance.penup()
  entrance.speed(0)
  entrance.color('#F54747')
  entrance.goto(-85, 100)
  entrance.write("Alien Shooter", font=(None, 25, "bold")
  entrance.time.sleep(0.5)
  entrance.color('#46F2AB')
  entrance.write("Alien Shooter", font=(None, 25, "bold")
  entrance.time.sleep(0.5)
  entrance.color('#F2E446')
  entrance.write("Alien Shooter", font=(None, 25, "bold")
  entrance.time.sleep(0.5)
  entrance.color('#F2466C')
  entrance.write("Alien Shooter", font=(None, 25, "bold")
  entrance_time=entrance_time-1
  entrance.time.sleep(1)

drawButton2 = turtle.Turtle()
drawButton2.hideturtle()
drawButton2.penup()
drawButton2.speed(0)
drawButton2.goto(-85, 67)
drawButton2.pendown()
drawButton2.pensize(4)
drawButton2.fillcolor('#2C6E00')
drawButton2.color('#2C6E00')
drawButton2.begin_fill()
drawButton2.left(90)
drawButton2.fd(26)
drawButton2.right(125)
drawButton2.fd(25)
drawButton2.right(113)
drawButton2.fd(24)
drawButton2.end_fill()

drawButton = turtle.Turtle()
drawButton.hideturtle()
drawButton.penup()
drawButton.speed(0)
drawButton.goto(-85, 70)
drawButton.pendown()
drawButton.pensize(4)
drawButton.fillcolor('#43A800')
drawButton.color('#43A800')
drawButton.begin_fill()
drawButton.left(90)
drawButton.fd(26)
drawButton.right(125)
drawButton.fd(25)
drawButton.right(113)
drawButton.fd(24)
drawButton.end_fill()
drawButton.penup()
drawButton.goto(-55, 74)
drawButton.color('#43A800')
drawButton.write("Press P to begin", font=(None, 13, "bold"))

highscores2 = turtle.Turtle()
highscores2.hideturtle()
highscores2.penup()
highscores2.speed(0)
highscores2.goto(93, 35)
highscores2.pendown()
highscores2.pensize(4)
highscores2.fillcolor('yellow')
highscores2.begin_fill()
highscores2.left(90)
highscores2.forward(23)
highscores2.left(90)
highscores2.forward(155)
highscores2.left(90)
highscores2.forward(23)
highscores2.left(90)
highscores2.forward(155)
highscores2.end_fill()
highscores2.penup()
highscores2.goto(-58, 41)
highscores2.color('black')
highscores2.write("Press H for highscores", font=(None, 10, "bold"))

highscores = turtle.Turtle()
highscores.hideturtle()
highscores.penup()
highscores.speed(0)
highscores.goto(93, 35)
highscores.pendown()
highscores.pensize(4)
highscores.fillcolor('yellow')
highscores.begin_fill()
highscores.left(90)
highscores.forward(23)
highscores.left(90)
highscores.forward(155)
highscores.left(90)
highscores.forward(23)
highscores.left(90)
highscores.forward(155)
highscores.end_fill()
highscores.penup()
highscores.goto(-58, 41)
highscores.color('black')
highscores.write("Press H for highscores", font=(None, 10, "bold"))

def startGame():
  backHigh.clear()
  highscores2.clear()
  drawButton2.clear()
  highscores.clear()
  drawButton.clear()
  startingTurtle.penup()
  startingTurtle.hideturtle()
  startingTurtle.color('green')
  startingTurtle.goto(100, 40)
  startingTurtle.dot(25)
  wn.onkey(None)

wn.onkey(startGame, "P")

def backHigh():
  drawButton = turtle.Turtle()
  drawButton.hideturtle()
  drawButton.penup()
  drawButton.speed(0)
  drawButton.goto(100, 70)
  drawButton.pendown()
  drawButton.pensize(4)
  drawButton.fillcolor('lightgreen')
  drawButton.begin_fill()
  drawButton.left(90)
  drawButton.forward(35)
  drawButton.left(90)
  drawButton.forward(170)
  drawButton.left(90)
  drawButton.forward(35)
  drawButton.left(90)
  drawButton.forward(170)
  drawButton.end_fill()
  drawButton.penup()
  drawButton.goto(-63, 80)
  drawButton.color('black')
  drawButton.write("Press P to begin", font=(None, 15, "bold"))

  highscores = turtle.Turtle()
  highscores.hideturtle()
  highscores.penup()
  highscores.speed(0)
  highscores.goto(93, 35)
  highscores.pendown()
  highscores.pensize(4)
  highscores.fillcolor('yellow')
  highscores.begin_fill()
  highscores.left(90)
  highscores.forward(23)
  highscores.left(90)
  highscores.forward(155)
  highscores.left(90)
  highscores.forward(23)
  highscores.left(90)
  highscores.forward(155)
  highscores.end_fill()
  highscores.penup()
  highscores.goto(-58, 41)
  highscores.color('black')
  highscores.write("Press H for highscores", font=(None, 10, "bold"))

  wn.onkey(startGame, "P")

  wn.onkey(lookHighscores, "H")

def lookHighscores():
  drawButton2.clear()
  drawButton.clear()
  highscores2.clear()
  highscores.clear()
  wn.onkey(None)
  wn.onkey(backHigh, "B")

wn.onkey(startGame, "P")
wn.onkey(lookHighscores, "H")
wn.listen()
wn.mainloop()

1 个答案:

答案 0 :(得分:2)

尝试在)行的末尾添加结束entrance.write。他们似乎失踪了。可能还有其他错误,但这应该解决其中一些错误。

至于您的P密钥无法正常工作。 P正在调用函数startGame。这似乎不是正确的功能。