samedi 9 février 2019

TURTLE - Change coordenates based on the length of a list, if statement, or while loop? turtle.goto()

This is the code for a calculator I made with Turtle, the list contains the different digits and operators to be used. The If statement checks the lenght of the list, and for every +1 element added to the list, it moves the coordenates of the turtle pen which will then write the numbers that were input by the user in a calculator "display".

How can a I make this code more efficient?

def order_display():
    if len(list) == 1:
        turtle.goto(250, 110)
    elif len(list) == 2:
        turtle.goto(235, 110)
    elif len(list) == 3:
        turtle.goto(215, 110)
    elif len(list) == 4:
        turtle.goto(200, 110)
    elif len(list) == 5:
        turtle.goto(185, 110)
    elif len(list) == 6:
        turtle.goto(170, 110)
    elif len(list) == 7:
        turtle.goto(155, 110)
    elif len(list) == 8:
        turtle.goto(140, 110)
    elif len(list) == 9:
        turtle.goto(125, 110)
    elif len(list) == 10:
        turtle.goto(110, 110)
    elif len(list) == 11:
        turtle.goto(95, 110)
    elif len(list) == 12:
        turtle.goto(80, 110)
    elif len(list) == 13:
        turtle.goto(65, 110)
    elif len(list) == 14:
        turtle.goto(50, 110)
    elif len(list) == 15:
        turtle.goto(35, 110)
    elif len(list) == 16:
        turtle.goto(20, 110)
    elif len(list) == 17:
        turtle.goto(5, 110)
    elif len(list) == 18:
        turtle.goto(-10, 110)
    else:
        print("DOES NOTHING")

Aucun commentaire:

Enregistrer un commentaire