Fun Python Project to Draw Shapes
Fun Python Project to Draw Shapes
Write a Python 3 function using the turtle library that allows users to draw geometric shapes. The function should prompt the user to input the desired shape and color, and then display the shape in the specified color. It is a fun Python project to practice using the turtle library, handling user input, and creating visual displays with Python.
Guidelines
Steps to complete the fun Python project to draw shapes:
- Import Necessary Modules:
- Import the
turtlemodule to utilize its drawing capabilities.
- Import the
- Define the Drawing Function:
- Create a function that takes the shape and color as input and uses the turtle module to draw the requested shape in the specified color.
- Prompt User Input:
- Ask the user to input the shape and color they want to display.
- Display the Shape:
- Utilize the turtle graphics to draw the requested shape in the specified color.
Source Code
import turtle
def draw_geometric_shape(shape, color):
window = turtle.Screen()
t = turtle.Turtle()
t.color(color)
if shape.lower() == "square":
for _ in range(4):
t.forward(100)
t.right(90)
elif shape.lower() == "triangle":
for _ in range(3):
t.forward(100)
t.left(120)
elif shape.lower() == "circle":
t.circle(50)
window.mainloop()
# Prompt user input
requested_shape = input("Enter the shape you want to draw (square, triangle, circle): ")
requested_color = input("Enter the color you want for the shape: ")
# Draw the requested shape in the specified color
draw_geometric_shape(requested_shape, requested_color)
If you liked this python project, try more difficult Python challenges like drawing the red cross logo or the olympic games symbol.
