Reputation: 3
I am trying to draw a turtle-graphics flower with num
petals. However, when I run my code I only get one single petal printed out. The error I get is under the def flower(num, i = 1)
part of the code, but I am not sure how I can fix it.
import time
from turtle import *
pensize(2)
pencolor("orange")
bgcolor("green")
fillcolor("blue")
hideturtle()
def halfPetal():
forward(50)
left(30)
forward(75)
left(30)
forward(50)
left(120)
def petal():
for i in range(2):
halfPetal()
def flower(num, i=1):
if i==1:
begin_fill()
for i in range(num):
petal()
left(360/petal())
end_fill()
flower(12)
time.sleep(10)
Upvotes: 0
Views: 1589
Reputation: 77910
At least one problem is at the line:
left(360/petal())
petal
does not return a value, so you're trying to divide by None
. There is no such operation in Python, so you get a fatal error. Instead, I think you need to divide by the quantity of petals you're going to draw:
left(360.0 / num)
Upvotes: 2