Drawing Stars with turtle in python
Question: I need to write a function that draws random stars based upon the question of
how many stars the person wants. a=color,b=length and c,d are the starting
coordinates. I am not really sure where I am going wrong any tips,hints or
help would be appreciated.

    
    
    import turtle
    from random import*
    def star(a,b,c,d):
        x=5
        y=0
        turtle.color(a)
        turtle.begin_fill()
        turtle.penup()
        turtle.goto(c,d)
        turtle.pendown()
        while x>0:
            turtle.forward(b)
            turtle.right(144)
            turtle.forward(b)
            x-=1
        turtle.end_fill()
    
    star('red',100,0,0)
    
    def random_color():
        randvar=randrange(0,5)
        if randvar==0:
            return ('red')
        elif randvar==1:
            return ('blue')
        elif randvar==2:
            return ('green')
        elif randvar==3:
            return ('yellow')
        else:
            return ('black')
    
    def length():
        randvar=randrange(5,71)
    
    def x():
        randvar=randrange(-280,281)
    
    def y():
        randvar=randrange(-200,201)
    
    def night_sky():
       z=int(input('How many stars do you want?'))
       a=random_color
       b=length
       c=x
       d=y
       while z>0:
           star(a,b,c,d)
           z-=1
    


Answer: To call a function, put parentheses after the function name:

    
    
       a=random_color()
       b=length()
       c=x()
       d=y()
    

* * *

Make sure you call `night_sky()` at the end of the script. Currently, only

    
    
    star('red',100,0,0)
    

is getting called. That's why you only see one star.

* * *

The functions `length`, `x` and `y` need to use `return`. Otherwise, `None` is
returned by default.

    
    
    def length():
        return randrange(5,71)
    
    def x():
        return randrange(-280,281)
    
    def y():
        return randrange(-200,201)
    

* * *

You need to move the statements defining `a`, `b`, `c`, and `d` into the
`while`-loop, lest the same star gets drawn `z` times. While we're at it, the
`while`-loop can be more simply written as a `for`-loop:

    
    
       for i in range(z):
           a=random_color()
           b=length()
           c=x()
           d=y()
           star(a,b,c,d)
    

* * *

Your code will become more self-documenting if you use more descriptive
variable names:

    
    
    def star(color, side_length, x, y):
        print(color, side_length, x, y)
        turtle.color(color)
        turtle.begin_fill()
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        for i in range(5):
            turtle.forward(side_length)
            turtle.right(144)
            turtle.forward(side_length)
        turtle.end_fill()
    

* * *

So with these changes, the code becomes:

    
    
    import turtle
    import random
    
    def star(color, side_length, x, y):
        print(color, side_length, x, y)
        turtle.color(color)
        turtle.begin_fill()
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        for i in range(5):
            turtle.forward(side_length)
            turtle.right(144)
            turtle.forward(side_length)
        turtle.end_fill()
    
    
    def random_color():
        randvar = randrange(0, 5)
        if randvar == 0:
            return ('red')
        elif randvar == 1:
            return ('blue')
        elif randvar == 2:
            return ('green')
        elif randvar == 3:
            return ('yellow')
        else:
            return ('black')
    
    
    def length():
        return random.randrange(5, 71)
    
    
    def xcoord():
        return random.randrange(-280, 281)
    
    
    def ycoord():
        return random.randrange(-200, 201)
    
    
    def night_sky():
        z = int(input('How many stars do you want?'))
        for i in range(z):
            color = random_color()
            side_length = length()
            x = xcoord()
            y = ycoord()
            star(color, side_length, x, y)
    
    night_sky()
    

