Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66957

Re: Functions help

Subject Re: Functions help
From Scott W Dunning <swdunning@cox.net>
Date 2014-02-23 18:24 -0700
References <mailman.7276.1393141556.18130.python-list@python.org> <VknC1n00H3bjUJS01knDZl>
Newsgroups comp.lang.python
Message-ID <mailman.7299.1393205088.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Feb 23, 2014, at 1:44 AM, Steven D'Aprano <steve+comp.lang.python@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)


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-22 22:43 -0700
  Re: Functions help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 08:44 +0000
  Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 10:55 +1000
    Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 01:09 +0000
      Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 11:39 +1000
        Re: Functions help Benjamin Kaplan <benjamin.kaplan@case.edu> - 2014-02-23 18:55 -0800
          Re: Functions help Grant Edwards <invalid@invalid.invalid> - 2014-02-24 15:38 +0000
        Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 03:21 +0000
          Re: Functions help rurpy@yahoo.com - 2014-02-23 20:01 -0800
            Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 13:59 +0000
            Re: Functions help Ethan Furman <ethan@stoneleaf.us> - 2014-02-25 18:52 -0800
              Re: Functions help rurpy@yahoo.com - 2014-02-26 17:06 -0800
        Re: Functions help MRAB <python@mrabarnett.plus.com> - 2014-02-24 03:36 +0000
      Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:43 -0700
      Re: Functions help Roy Smith <roy@panix.com> - 2014-02-23 20:28 -0500
    Re: Functions help Travis Griggs <travisgriggs@gmail.com> - 2014-02-23 17:27 -0800
  Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-24 01:01 +0000
    Re: Functions help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-24 21:18 -0500
      Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-27 22:49 +0000
  Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:24 -0700
  Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:15 -0800
  Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:32 -0800

csiph-web