Professional Documents
Culture Documents
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.
Def main()
Menu print user function options
Function definitions
Turtle loop
Main()
Part Two: Code the program.
Use the following guidelines to code your program.
Example of expected output: The screen shot below is an example of a menu. Your specific
results will vary depending on the choices you make. This sample moves the turtle forward,
backward, left, or right based on user input of F, B, L, or R, which are the menu options. The user
inputs Q to quit.
Insert your program code here:
import turtle
t = turtle.Turtle()
t.penup()
t.setposition(100, 100)
t.pendown()
t.color("blue")
t.circle(50)
ben = turtle.Turtle()
ben.penup()
ben.setposition(-100, -100)
ben.pendown()
ben.shape("turtle")
ben.color("green")
def printMenu():
""" This function prints the menu to the screen """
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("~ How to Naviagte Turtle to Pond")
print("~ F: Up")
print("~ L: Left")
print("~ B: Down")
print("~ R: Right")
print("~ Q: Quit")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
def main():
choice = "-1"
while(choice != "q"):
printMenu()
choice = input("Look at the movement guide. In which direction would you like to move in? F,
B, L, or R. Select Q to exit. (make sure to type in lowercase)")
if(choice == "f"):
ben.setheading(90)
ben.forward(50)
elif(choice == "l"):
ben.setheading(180)
ben.forward(50)
elif(choice == "b"):
ben.setheading(270)
ben.forward(50)
elif(choice == "r"):
ben.setheading(0)
ben.forward(50)
elif(choice == "q"):
print("Thank you!")
else:
print("Oops, an invalid option was picked. Please try again.")
main()
How could your program be useful in This program could be used to move a variety of things.
the real world?
What is a problem you ran into, and how A problem I ran into was figuring out how to implement user
did you fix it? key interaction into the program. I solved it by using an
example found in the lesson.
Describe one thing you would do I would make the program more direct, so that you would not
differently the next time you write a be interrupted by the query box and would be able to control
program. the turtle using direct commands.