乌龟模块错误与颜色()

时间:2014-07-28 20:35:41

标签: python python-3.x

我正在尝试编写一个程序让用户指定行的颜色,但我一直收到错误。有人可以解释为什么会发生这种情况

import turtle 
wn = turtle.Screen()
alex = turtle.Turtle
sides = int(input("Enter the number of sides: "))
angle = 360/ sides
length = int(input("Enter the length of sides: "))
line_color = input("Enter the color of the lines: ")
alex.color(line_color)

fill_color = input("Enter the fill color for the polygon:" )
alex.fillcolor(fill_color)
alex.begin_fill()
for i in range(sides):
        alex.forward(lenght)
        alex.left(angle)
alex.end_fill()

2 个答案:

答案 0 :(得分:0)

这应该运行:

import turtle    

wn = turtle.Screen()    
alex = turtle.Turtle() # need parens    
sides = int(input("Enter the number of sides: "))    
angle = 360 / sides    
length = int(input("Enter the length of sides: "))    
line_color = input("Enter the color of the lines: ") # takes input like "red" or "black" etc.. 
alex.color(line_color)    
fill_color = input("Enter the fill color for the polygon:" )    
alex.fillcolor(fill_color)    
alex.begin_fill()    
for i in range(sides):    
        alex.forward(44)  # added 44, you had an undefined variable there which is not valid    
        alex.left(angle)    
alex.end_fill()

我添加了值44,您必须自己添加所需内容或将变量length初始化为某个值。

答案 1 :(得分:0)

你和朋友有错字。 alex.forward(length)