Drawing stars around the center of the screen I have an homework as follows:


  Write a program where you enter from the keyboard a number n. Then n
  stars are drawn onto the screen, circling around the center of your
  screen. You can assume that 1 &lt; n &lt; 20.


The solution I came up with is below.

import turtle

window=turtle.Screen()
window.screensize(1200,1200)

draw=turtle.Turtle()
draw.pensize(2)

draw.speed('fastest')

angle = [36,144,144,144,144]

GetNumber = int(input("Enter a number: "))

while GetNumber &lt;= 1 or GetNumber &gt;= 20:
    print("Enter a number between from 2 to 19")
    GetNumber = int(input("Enter a number: "))

for shape in range(GetNumber):
    for i in angle:
        draw.left(i)
        draw.forward(180)
    draw.penup()
    draw.forward(60)
    draw.pendown()
    draw.left(170)


Is there any way to improve this code? I think my code is OK, but I believe there are perhaps more concise or better solutions (working faster perhaps?)

Perhaps angle (currently 170) should be changed or perhaps an dynamic angle changer code can be implemented for the sake of improving the solutions. What do you think?
It would be user friendly and make testing easier if the program accepted the input number as a command line argument too, for example:

import sys


def main():
    if sys.argv[1:]:
        num = int(sys.argv[1])
        if not is_valid_number(num):
            warn_invalid_number()
            sys.exit(1)
    else:
        num = prompt_valid_number()

    draw_stars_in_a_spiral(num)

if __name__ == '__main__':
    main()


While doing this, to avoid code duplication, I split the original functionality to multiple functions, which is a good practice in general anyway.

For validating the number, the N &lt; var &lt; M operator of Python is very handy:

def is_valid_number(num):
    return 1 &lt; num &lt; 20


Then the warning and prompting functions:

def warn_invalid_number():
    print("Number must between 2 to 19 (inclusive)")    


def prompt_number():
    return int(input("Enter a number: "))


When prompting the user until he gives a valid number, change to a while True loop to avoid the duplication when asking for a number:

def prompt_valid_number():
    while True:
        num = prompt_number()
        if is_valid_number(num):
            return num
        warn_invalid_number()


Finally, the main method to draw the stars:

def draw_stars_in_a_spiral(num):
    window = turtle.Screen()
    window.screensize(1200, 1200)

    draw = turtle.Turtle()
    draw.pensize(2)

    draw.speed('fastest')

    for _ in range(num):
        for angle in angles:
            draw.left(angle)
            draw.forward(180)
        draw.penup()
        draw.forward(60)
        draw.pendown()
        draw.left(170)


Some points to note:


I moved all the drawing operations here. If validation fails when invoking with command line parameters, there's no need to open a window and draw anything.
I replaced the unused shape variable in for shape in range(num) with _
I replaced the angle array with angles to be more intuitive, and the loop variable i with the more intuitive name angle