截至目前,我需要编写一个脚本,提示用户选择 1或2,1创建使乌龟绘制一个三角形,2使它绘制一个正方形,到目前为止我所拥有的是。
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()
我运行脚本,shell中出现的是:
Click Either 1 or 2 To Chose Which To Draw
1. Triangle
2. Square
Enter your choice [1-2] :
然而,在冒号后如果你输入1或2,龟会发生什么?
答案 0 :(得分:1)
您的程序正常运行但在显示输出之前结束。您应该暂停程序的控制,以便用户可以先看到输出。最好的方法是在程序结束时添加以下一行代码 -
window.exitonclick()