231k views
1 vote
Write a program to move the Turtle based on the user’s request. Display a menu with options for the user to choose. Use the following guidelines to write your program.

1. Create a menu that gives the user options for moving the Turtle. The menu should contain letters or numbers that align with movements such as forward, backward, and/or drawing a particular pattern.

2. Use at least one if-else or elif statement in this program. It should be used to move the Turtle based on the user's input.

3. A loop is optional but may be used to ask the user to select multiple choices.

4. Use one color other than black.

2 Answers

2 votes

Final answer:

The program provides a menu-driven approach allowing users to control Turtle movements in Python. Utilizing a loop and if-else statements, users can command the Turtle to move forward, backward, turn, draw a circle, or exit. A blue-colored Turtle ensures compliance with the instructions.

Step-by-step explanation:

The task requires us to write a program using the Turtle graphics library in Python. The program should display a menu with options for the user to control the movements of the Turtle. Here is a simple example of how we could accomplish this task:

import turtle

# Set up the Turtle
scr = turtle.Screen()
scr.bgcolor("white")
t = turtle.Turtle()
t.color("blue")

# Function to display the menu
def display_menu():
print("Options:")
print("1. Move Forward")
print("2. Move Backward")
print("3. Turn Left")
print("4. Turn Right")
print("5. Draw Circle")
print("6. Exit")

running = True
while running:
display_menu()
choice = input("Enter your choice:")
if choice == '1':
t.forward(100)
elif choice == '2':
t.backward(100)
elif choice == '3':
t.left(90)
elif choice == '4':
t.right(90)
elif choice == '5':
t.circle(50)
elif choice == '6':
running = False
else:
print("Invalid choice, please select a valid option.")

# Close the window on click
scr.exitonclick()

In this program, we define a menu for the user with options that include moving forward, backward, turning left or right, drawing a circle, and exiting the program. We use an if-else statement to determine the Turtle's movement based on the user's choice. The user can make multiple choices in a loop until they decide to exit by choosing the "Exit" option. The Turtle is set to blue color to fulfill the requirement of using a color other than black.

User Miholzi
by
5.2k points
12 votes

Answer:

#import turtle

import turtle

# set screen

Screen = turtle.Turtle()

# decide colors

cir= ['red','green','blue','yellow','purple']

# decide pensize

turtle.pensize(4)

# Draw star pattern

turtle.penup()

turtle.setpos(-90,30)

turtle.pendown()

for i in range(5):

turtle.pencolor(cir[i])

turtle.forward(200)

turtle.right(144)

turtle.penup()

turtle.setpos(80,-140)

turtle.pendown()

# choose pen color

turtle.pencolor("Black")

# importing turtle module

import turtle

# number of sides

n = 10

# creating instance of turtle

pen = turtle.Turtle()

# loop to draw a side

for i in range(n):

# drawing side of

# length i*10

pen.forward(i * 10)

# changing direction of pen

# by 144 degree in clockwise

pen.right(144)

# closing the instance

turtle.done()

turtle.done()

Step-by-step explanation:

User ScottL
by
4.8k points