-1
# Module Inputs
import turtle

# Define Functions
def drawshape(s,l,c):
    angle = 360 / s
    a.pencolor(c)
    for i in range(s):
        a.forward(l)
        a.left(angle)

# Create Turtle
a = turtle.Turtle
a.pensize(5)
a.pendown()

# Title and Credits
print('Shape Drawer by Alex Thornton')

# While Loop
answer = 'y'
while True:
    if answer != 'y':
        break

    # Create Turtle Window
    wn = turtle.Screen()

    # Inputs
    sides = int(input("\nHow many sides? ")
    length = int(input('What length of sides? ')
    color = input('What colour? ')

    # Call Functions from Inputs
    drawshape(sides,length,color)

    # Exit (From Turtle Window)
    wn.exitonclick()

    # Input For Restart
    answer = input("\nAgain? (y/n) ")

# Exit Program
print("\nThank you for using this program!")
exit = input('Please press enter to exit.')

在长度输入上,我在第 31 行收到错误输入的解析错误。该程序从用户那里获取边长、边数和形状颜色的输入。这是作为 GCSE 计算作业完成的。

4

1 回答 1

3

您在第 30 行和第 31 行缺少括号。由于行不完整,在提到的上一行经常出现解析错误。

sides = int(input("\nHow many sides? "))
length = int(input('What length of sides? '))

第 13 行也需要括号来创建Turtle.

a = turtle.Turtle()
于 2013-09-13T15:46:34.403 回答