I have been developing a fairly simple turtle program which essentially just draws snowflakes of a random size, shape, and colour. The amount is based on user input. What I would like to do with the program is add an input section at the end that asks the user whether they would like to end the program or restart it. If they choose restart, the program should start over again from the beginning. Otherwise it should follow the exit procedure I made for it. I have seen methods including WHILE Loops and other similar concepts, I just can't figure out how to apply it to my code. Is there a simple way to do this?
Here is the code:
import time
import sys
import turtle
import random
n = int(input("How many snowflakes do you want?: "))
screen = turtle.Screen()
screen.bgcolor("black")
speedy = turtle.Turtle()
speedy.speed(0)
sfcolor = ["yellow","gold","orange","red","violet","magenta","purple","navy","blue","skyblue","cyan","turquoise","lightgreen","green","darkgreen","white"]
def snowflake(size):
speedy.penup()
speedy.forward(10 * size)
speedy.left(45)
speedy.pendown()
speedy.color(random.choice(sfcolor))
for i in range(8):
branch(size)
speedy.left(45)
def branch(size):
for i in range(3):
for i in range(3):
speedy.forward(10.0 * size / 3)
speedy.back(10.0 * size / 3)
speedy.right(45)
speedy.left(90)
speedy.back(10.0 * size / 3)
speedy.left(45)
speedy.right(90)
speedy.forward(10.0 * size)
for i in range(n):
x = random.randint(-200, 200)
y = random.randint(-200, 200)
sfsize = random.randint(1, 4)
speedy.penup()
speedy.goto(x, y)
speedy.pendown()
snowflake(sfsize)
print("The turtle window will close in 10 seconds. Thanks for using the program!")
print("Goodbye!")
time.sleep(10)
turtle.Screen().bye()
sys.exit()