Functions help

Scott W Dunning swdunning at cox.net
Mon Feb 24 02:24:44 CET 2014


On Feb 23, 2014, at 1:44 AM, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> 
> Sorry, I don't really understand your question. Could you show an example 
> of what you are doing?
> 
> Do you mean "add 5" or "*5"?  "Add *5 doesn't really mean anything to me.
Sorry I forgot to add the code that I had to give an example of what I was talking about.  I’ll put it below, sorry that it’s so long.  A couple of people have basically answered my question though.  I take it was I was talking about was a loop, which I haven’t learned in school yet but, it seems semi self-explanatory.   As you can see I added a loop in there about half way down the code (i put it in bold) and it seemed to do what I want.  Now I’m going to try and do what Rhodri suggested, a range function?  I’m not sure exactly what that’ll do but I think it’ll clean up my code more and make things easier to call?  

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)

for i in range (5):
    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)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140223/b368e2aa/attachment.html>


More information about the Python-list mailing list