[Tutor] Function help
Scott W Dunning
swdunning at cox.net
Sun Feb 23 09:17:43 CET 2014
On Feb 23, 2014, at 1:12 AM, Scott W Dunning <swdunning at cox.net> wrote:
> I am VERY new to python (programming too). I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? I am trying to code an American Flag using turtle for class so I’ll post the code I have so far below. As you can see towards the bottom I recall the functions to draw the stars, fill in color and give it spacing. I was wondering if there was a way to cut down on all that some how?
>
> Thanks for any help!
>
> Scott
from turtle import *
from math import sin, sqrt, radians
def star(width):
R = (width)/(2*sin(radians(72)))
A = (2*width)/(3+sqrt(5))
penup()
left(18)
penup()
forward(R)
pendown()
left(162)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
penup()
left(162)
forward(R)
left(162)
showturtle()
def fillstar(color):
fillcolor(color)
begin_fill()
star(25)
end_fill()
red = "red"
fillstar(red)
def space(width):
penup()
forward(2*width)
pendown()
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
def row(width):
penup()
right(90)
forward(width)
right(90)
forward(11*width)
right(180)
pendown()
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
row(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
More information about the Tutor
mailing list