import math import turtle # functions go here... # Functions go here def string_check(question, valid_ans_list, num_letters): """Checks that users enter the full word or the 'n' letter/s of a word from a list of valid responses""" while True: response = input(question).lower() for item in valid_ans_list: if response == item: return item elif response == item[:num_letters]: return item print(f"Please choose an option from the list {valid_ans_list}") # Functions go here def int_check(question, low, high): error = f"Oops - please enter an number that is higher or equal to {low} and lower or equal to {high} ." while True: try: response = float(input(question)) if response >= low <= high: return response else: print(error) except ValueError: print(error) shape_list = ["circle", "square", "rectangle", "parallelogram", "exit"] while True: shape_select = string_check("Pick a shape: ", shape_list, 1) print(f"You chose {shape_select}") if shape_select == shape_list[0]: radius = int_check("Enter radius: ", 1, 100) circumference = 2 * math.pi * radius area = math.pi * radius * radius shape = 'circle' circumference_round = round(circumference, 2) area_round = round(area, 2) print(f' The circumference of the circle is:{circumference_round}') print(f' The area of the circle is:{area_round}') turtle.circle(radius) turtle.exitonclick() elif shape_select == shape_list[1]: length = int_check("enter the size of your side: ", 0.1, 100) area = length * length shape = 'square' perimeter = length + length + length + length area_round = round(area, 2) perimeter_round = round(perimeter, 2) print(f' The area of the square is:{area_round}') print(f' The perimeter of the square is:{perimeter_round}') elif shape_select == shape_list[2]: first_length = int_check("enter the size of your first side: ", 0.1, 100) second_length = int_check("enter the size of your second side: ", 0.1, 100) area = first_length * second_length perimeter = first_length + first_length + second_length + second_length shape = 'rectangle' area_round = round(area, 2) perimeter_round = round(perimeter, 2) print(f' The area of the rectangle is:{area_round}') print(f' The perimeter of the rectangle is:{perimeter_round}') elif shape_select == shape_list[3]: length = int_check("enter the size of your side: ", 0.1, 100) height = int_check("enter the height of your shape: ", 0.1, 100) area = length * height perimeter = length + length + length + length shape = 'parallelogram' area_round = round(area, 2) perimeter_round = round(perimeter, 2) print(f' The area of the parallelogram is:{area_round}') print(f' The perimeter of the parallelogram is:{perimeter_round}')