mardi 22 septembre 2015

Python - Simple turtle program

I am trying to make a program that when run, creates either a line, square, or triangle in turtle.

I have created programs and if statements for each shape. I cannot figure out what is stopping my turtle programs from utilizing the inputted length.

My program:

def Makeashape():
    color = input('What color?')
    width = input('How wide?')
    size = input('How long?')
    shape = input('What shape would you like to make?')
    import turtle
    t = turtle.Turtle()
    s = turtle.Screen()

def line(width, size, color):
    t.color(color)
    t.width(width)
    t.fd(size)

def triangle(width, size, color):
    for i in range(3):
        t.color(color)
        t.width(width)
        t.fd(size)
        t.rt(120)

def square(width, size, color):
    for i in range(4):
        t.color(color)
        t.width(width)
        t.fd(size)
        t.rt(90)

if shape == 'triangle':
    triangle(width, size, color)
elif shape == 'square':
    square(width, size, color)
elif shape == 'line':
    line(width, size, color)

Makeashape()

Aucun commentaire:

Enregistrer un commentaire