mardi 15 novembre 2016

Cant get while loop to work properly in python

Im trying to make a menu to draw shapes using turtle and if they make a wrong selection i want it to run the menu again. It only outputs a blank window though. If i take out the while loop its works fine.

import turtle


def drawSquare():
    for i in range(4):
        pen.forward(100)
        pen.left(90)

def drawCircle():
    pen.circle(50)

def drawTriangle():
    for i in range(3):
        pen.forward(100)
        pen.left(120)

def drawRectangle():
    for i in range(2):
        pen.forward(150)
        pen.left(90)
        pen.forward(100)
        pen.left(90)

choice = int(input("Menu Options.""\n"
"-----------------""\n"
"Enter 1 for a Square""\n"
"Enter 2 for a Circle""\n"
"Enter 3 for a Triangle""\n"
"Enter 4 for a Rectangle"))


pen= turtle.Turtle()

window = turtle.Screen()

pen.shape("turtle")
pen.hideturtle()
pen.color("blue")
pen.pensize(5)

count = 1
while (count ==2):
    if (choice == 1):
        drawSquare()
        count = count + 1

    elif (choice == 2):
        drawCircle()
        count = count + 1

    elif (choice == 3):
        drawTriangle()
        count = count + 1

    elif (choice == 4):
        drawRectangle()
        count = count + 1


    else:
        choice = int(input("Please pick again""\n"
        "-----------------""\n"
        "Enter 1 for a Square""\n"
        "Enter 2 for a Circle""\n"
        "Enter 3 for a Triangle""\n"
        "Enter 4 for a Rectangle"))

window.mainloop()

Aucun commentaire:

Enregistrer un commentaire