Reputation: 7
So as of now, I need to write a script prompting a user to select either 1 or 2, 1 creates makes the turtle draw a triangle, and 2 makes it draw a square, so far what I have is.
import turtle
window = turtle.Screen()
rex = turtle.Turtle()
rex.pensize(2)
rex.pencolor("black")
rex.fillcolor("white")
rex.pendown()
rex.begin_fill()
print (40 * '-')
print ("Click Either 1 or 2 To Chose Which To Draw")
print (40 * '-')
print ("1. Triangle")
print ("2. Square")
choice = input('Enter your choice [1-2] : ')
choice = int(choice)
if choice == 1:
rex.forward(90)
rex.left(120)
rex.forward(90)
rex.left(120)
rex.forward(90)
rex.left(120)
rex.end_fill()
rex.penup()
elif choice == 2:
rex.forward(100)
rex.left(90)
rex.forward(100)
rex.left(90)
rex.forward(100)
rex.left(90)
rex.forward(100)
rex.left(90)
rex.end_fill()
rex.penup()
I run the script, and what comes out in the shell is:
Click Either 1 or 2 To Chose Which To Draw
1. Triangle
2. Square
Enter your choice [1-2] :
however, after the colon if you type 1 or 2, nothing on turtle happens?
Upvotes: 0
Views: 7648
Reputation: 6950
Your program works correctly but it ends before displaying the output. You should pause the control of the program so that user can see the output first. Best way is to add the following one line of code at the end of your program -
window.exitonclick()
Here is the documentation.
Upvotes: 1