我的龟是死的!他不会用我的循环画画。 nmbrOfSides
正在返回3
BTW。关于我可能会忽略的任何暗示?
import turtle
counter = 0
def poly_side_calculation (student_number):
sides = 3 + student_number % 3
return sides ####function returns 3 when I enter student number
print("welcome to my TURTLE demonstration.\n")
studentNmbr = int(input("Please enter your student number to get started: " ))
print("Here are your choices for the color of your polygon. You can choose red, green, blue, yellow, cyan, magenta, black or white.")
fill_color = input("Please enter the color that you would like your polygon to be: ")
poly_side_length = int(input("Please enter the length of your polygon side: "))
nmbrOfSides = poly_side_calculation(studentNmbr)
vertex_angle = 360 / nmbrOfSides
turtle.color("black", fill_color)
turtle.pensize(5)
turtle.showturtle()
turtle.pendown()
turtle.begin_fill()
turtle.setpos(-150,150)
while counter <= nmbrOfSides:
turtle.forward = (poly_side_length)
turtle.left = vertex_angle
counter = counter + 1
turtle.end_fill()
答案 0 :(得分:2)
turtle.forward = (poly_side_length)
turtle.left = vertex_angle
这不符合你的想法。您需要调用函数,而不是分配给它们:
turtle.forward(poly_side_length)
turtle.left(vertex_angle)
粗略地说,你告诉乌龟“前进50像素”而不是“前进50像素”,乌龟正在重新定义“前进”意味着而不是移动的概念。
答案 1 :(得分:0)
Python从左到右评估方程,但有些操作优先(类似于PEMDAS)。
您的模数运算正在总和之前进行评估。尝试用括号计算它:
sides = (3 + student_number) % 3
student_number=0
应该返回1