Fop If Else Elif
Fop If Else Elif
02 More Decisions
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.
5. Write the pseudocode for this program. Be sure to include any needed
input, calculations, and output.
import turtle
def main():
# Setup the turtle
my_turtle = turtle.Turtle()
program_running = "true"
# Main loop
while(program_running == "true"):
user_input = input("Enter your choice: ")
if user_input == 'F':
my_turtle.forward(100)
elif user_input == 'B':
my_turtle.backward(100)
elif user_input == 'L':
my_turtle.left(90)
elif user_input == 'R':
my_turtle.right(90)
elif user_input == 'C':
change_color(my_turtle)
elif user_input == 'S':
draw_square(my_turtle)
elif user_input == 'T':
draw_triangle(my_turtle)
elif user_input == 'O':
draw_circle(my_turtle)
elif user_input == 'Q':
print("Thank you for drawing with us.")
program_running = False
else:
print("Invalid input, please choose from the menu options.")
main()
How could your program be When expanded, this can be used to draw much
useful in the real world? more complicated things, benefitting many more
people.
What is a problem you ran into, A problem I ran into was a syntax error in the
and how did you fix it? while loop condition. I originally wrote a single
equals sign for assignment instead of a double
equals sign for comparison. I fixed this by adding
a double equals sign and also added the colon.
Describe one thing you would do Next time, I would focus on improving input
differently the next time you validation and error handling to make the
write a program. program better. This includes ensuring that user
inputs are validated properly, especially when
changing colors or drawing shapes, and
implementing better error messages for
unexpected inputs. Additionally, I would explore
adding more interactive features to enhance
user engagement and usability.