use inputs to print figures with turtle

0

I am a beginner in pyhton I am working in turtle I must do a program to ask the user what figure wants to draw and make that figure importing turtle, until now I have defined the figures for the answers but how do I do it so that when the user puts the name of the defined figure is printed example:

"which figure wants to draw" t (or triangle)

(here the figure)

This is the code I have:

import turtle

input("que figura quiere dibujar")

def cuadrado():
    turtle.pen()
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)

def triangulo():
    turtle.pen()
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    
asked by Spiral 15.11.2016 в 18:58
source

1 answer

0

you could try the following:

import turtle

def cuadrado():
    turtle.pen()
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)

def triangulo():
    turtle.pen()
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)

opciones = ['Cuadrado', 'Triangulo']
print('Opciones posibles', opciones)
eleccion = input("que figura quiere dibujar:")

if eleccion == "Cuadrado":
    cuadrado()
else:
    triangulo()

Obviously this solution that I give is very simple, it could be improved by giving the list of options and validating it so that there are no exceptions.

    
answered by 15.11.2016 в 23:24