0% found this document useful (0 votes)
14 views5 pages

Fop If Else Elif

Uploaded by

Dhruv Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Fop If Else Elif

Uploaded by

Dhruv Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name______________________________ 04.

02 More Decisions

This assignment has three parts.

Part One: Programming

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.

Insert your pseudocode here:

1. Ask user what action they want to do


2. Keep repeating loop until ended
3. Thank user for drawing with us.

Part Two: Code the program.


Use the following guidelines to code your program.

1. To code the program, use the Python IDLE.


2. Using comments, type a heading that includes your name, today’s date,
and a short description of the program.
3. Follow the Python style conventions regarding indentation and the use of
white space to improve readability.
4. Use meaningful variable names.

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:

# Name: Dhruv Gupta


# Date: 7/1/2024

import turtle

def main():
# Setup the turtle
my_turtle = turtle.Turtle()

# Function to change the turtle's color


def change_color(turtle):
new_color = input("Enter a new color: ")
turtle.color(new_color)

# Function to draw a square


def draw_square(turtle):
for sqr in range(4):
turtle.forward(100)
turtle.right(90)

# Function to draw a triangle


def draw_triangle(turtle):
for tri in range(3):
turtle.forward(100)
turtle.left(120)

# Function to draw a circle


def draw_circle(turtle):
turtle.circle(50)

# Display menu options


print("Menu:")
print("F - Move Forward")
print("B - Move Backward")
print("L - Turn Left")
print("R - Turn Right")
print("C - Change Color")
print("S - Draw Square")
print("T - Draw Triangle")
print("O - Draw Circle")
print("Q - Quit")

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()

Part Three: Post Mortem Review


Complete the Post Mortem Review (PMR). Write thoughtful two to three sentence
responses to all the questions in the PMR chart.
Review Question Response
What was the purpose of your The program's purpose was to allow users to
program? control a turtle graphic interactively, offering
additional functionalities such as drawing
shapes, changing colors, and drawing circles.

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.

You might also like