(Solved) : Lot Trouble Trying Call Methods Main Function User Input 3 4 Display Problem Statement Cod Q29963714 . . .
I am having a lot of trouble trying to call my methods into mymain function for user input 3 and 4. I will display the problemstatement and then my code along with it.
Create a program that uses Turtle to draw shapes. Show thefollowing menu: 1) Enter Circle 2) Enter Rectangle 3) Sort Shapes4) Draw Shapes 5) Exit Circles – User inputs position, radius, andcolor. The position is the center of the circle Rectangles – Userinputs position, height, width, color. The position is the lowerleft-hand corner Colors – Allow red, yellow, blue, and green onlySort – Sort by: area of the shape; color (give the user the choiceof colors); original input order Draw Shapes – Draw the shapes inthe order they are in the list Guidelines • Create a class calledCircle in its own file • Create a class called Rectangle in its ownfile • In each class create a method called draw() that will drawthe shape (as well as anything else you need) • Store all Circleand Rectangle objects in a single list • Use a selection sort tosort the list • Use a loop to draw all of the shapes
# Create a program that uses Turtle to draw shapes.import turtlefrom circle import Circlefrom rectangle import Rectangledef selection_sort_order(input_list): for i in range(len(input_list) – 1): curr_object = i for j in range(i + 1, len(input_list)): if input_list[curr_object] > input_list[j]: curr_object = j if curr_object != i: input_list[i], input_list[curr_object] = input_list[curr_object], input_list[i]def selection_sort_area(lst_area): for i in range(len(lst_area) – 1): curr_object = i for j in range(i + 1, len(lst_area)): if lst_area[curr_object] > lst_area[j]: curr_object = j if curr_object != i: lst_area[i], lst_area[curr_object] = lst_area[curr_object], lst_area[i]def selection_sort_color(color_lst): for i in range(len(color_lst)-1): curr_object = i for j in range(i + 1, len(color_lst)): if color_lst[curr_object] > color_lst[j]: curr_object = j if curr_object != i: color_lst[i], color_lst[curr_object] = color_lst[curr_object], color_lst[i]def main(): color_list = [“red”, “yellow”, “blue”, “green”] list_of_objects = [] lst_area = [Circle.get_area_circle, Rectangle.get_area_rectangle] print(“Menu:” “n1) Enter Circle” “n2) Enter Rectangle” “n3) Sort Shapes” “n4) Draw Shapes” “n5) Exit”) while True: user_input = eval(input(“Please enter a number from the menu displayed above: “)) if user_input == 1: position = eval(input(“Please enter a position: “)) radius = eval(input(“Please enter a radius: “)) while True: color = input(“Please enter a color(red, yellow, blue, green): “) if color in color_list: break else: print(“invalid color, please select a color form the following options.”) circ = Circle(position, radius, color) list_of_objects.append(circ) if user_input == 2: position = eval(input(“Please enter a position: “)) height = eval(input(“Please enter a height: “)) width = eval(input(“Please enter a width: “)) while True: color = input(“Please enter a color(red, yellow, blue, green): “) if color in color_list: break else: print(“invalid color, please select a color form the following options.”) rec = Rectangle(position, height, width, color) list_of_objects.append(rec) if user_input == 3: selection_sort_area(lst_area) selection_sort_order(input_list) selection_sort_color(color_list) for input_list in list_of_objects: print(input_list) for lst_area in list_of_objects: print(lst_area) for color_list in list_of_objects: print(color_list) if user_input == 4: turtle.showturtle() circ = Circle() circ.draw() turtle.hideturtle() turtle.showturtle() rec = Rectangle() rec.draw() turtle.hideturtle() if user_input == 5: breakmain()
# the circle file
import turtleimport mathclass Circle: def __init__(self, radius=(), position=(), color=()): self.radius = radius self.position = position self.color = color def draw(self): turtle.penup() turtle.goto(self.position) turtle.pendown() turtle.fillcolor(self.color) turtle.begin_fill() turtle.circle(self.radius) turtle.end_fill() def get_area_circle(self): return math.pi * self.radius ** 2
#the rectangle file
import turtleclass Rectangle: def __init__(self, position=(), height=(), width=(), color=()): self.position = position self.height = height self.width = width self.color = color def draw(self): turtle.penup() turtle.goto(self.position) turtle.begin_fill() turtle.fillcolor(self.color) turtle.pendown() turtle.forward(self.width) turtle.left(90) turtle.forward(self.height) turtle.left(90) turtle.forward(self.width) turtle.left(90) turtle.forward(self.height) turtle.end_fill() def get_area_rectangle(self): return width * height
.
Expert Answer
Answer to Lot Trouble Trying Call Methods Main Function User Input 3 4 Display Problem Statement Cod Q29963714 . . .
OR