Python - drawing a flower with turtle by recursive function
up vote
0
down vote
favorite
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)
python turtle-graphics
add a comment |
up vote
0
down vote
favorite
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)
python turtle-graphics
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
1
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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)
python turtle-graphics
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)
python turtle-graphics
python turtle-graphics
edited Nov 7 at 18:58
Prune
41.1k133454
41.1k133454
asked Nov 7 at 18:47
stabekk
31
31
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
1
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09
add a comment |
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
1
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
1
1
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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)
add a comment |
up vote
2
down vote
accepted
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)
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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)
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)
answered Nov 7 at 18:55
Prune
41.1k133454
41.1k133454
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195868%2fpython-drawing-a-flower-with-turtle-by-recursive-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. This generally includes the full error message.
– Prune
Nov 7 at 18:56
@Prune im pretty sure there is no error ... it just does not draw the image OP expcted... he did not do a good job of describing his expected output
– Joran Beasley
Nov 7 at 19:35
1
@JoranBeasley: the posted code faults with the error I cited. Also, note that OP says "The error I get ..."
– Prune
Nov 7 at 20:09