# Imports go here from math import pi # Functions go here def num_check(question, low, high): """Checks users enter an integer between two values""" error = f"Oops - please enter a whole number between {low} and {high}" while True: try: # Change the response to an integer and check that it's more than zero response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def make_statement(statement, decoration, lines=1): """Creates headings (3lines), subheadings (2 lines) and emphasized text / mini-headings (1 line). Only use emoji for single line statements""" middle = f"{decoration * 3} {statement} {decoration * 3}" top_bottom = decoration * len(middle) if lines == 1: print(middle) elif lines == 2: print(middle) print(top_bottom) else: print(top_bottom) print(middle) print(top_bottom) def string_check(question, valid_ans_list, num_letters): """Checks that the 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: # check if the response is the word if response == item: return item # check if it's the 'n' letter elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_ans_list}") # Variables yes_no = ["yes", "no"] shapes_list = ["square", "rhombus", "rectangle", "circle"] area_perimeter = ["area", "perimeter", "circumference"] # Main Routine goes here ask_option = string_check("Would you like to start the code?: ", yes_no, 1) print() while ask_option == "yes": want_instructions = string_check("Do you want to see the instructions? ", yes_no, 1) print() print(f"You chose {want_instructions}") if want_instructions == "yes": print() make_statement("Instructions", "📄", 1) print("Enter the shape that you are working on and then enter the numbers for the different sides") print("and parts of measurements that you know, then program will do the work for you. ") print("We are still in beta so we only have a few 2D shapes including:") print("Square, Rhombus, Rectangle, and Circle. Thanks for understanding. 😊") print() while ask_option == "yes": shape_checker = string_check("Please choose a shape: ", shapes_list, 3) print(f"You chose {shape_checker}") print() if shape_checker == "square": length_square = num_check("Please enter the length of side № 1: ", 1, 50) print() print(f"The perimeter of your square is {length_square*4} and the area of your square is {length_square*2}") elif shape_checker == "rhombus": side_bus = num_check("Please enter one of the sides of your rhombus: ", 1, 50) print() length_bus = num_check("Please enter the length of your rhombus: ", 1, 50) print() height_bus = num_check("Please enter the height of your rhombus: ", 1, 50) print() print(f"The perimeter of your rhombus is {side_bus*4}, and the area of your rhombus is ") print(f"{(length_bus*height_bus)/2}") elif shape_checker == "rectangle": length_rec = num_check("Please enter the length of side № 1: ", 1, 50) print() length_rec2 = num_check("Please enter the length of side № 2: ", 1, 50) print() print(f"The perimeter of you rectangle is {length_rec*2 + length_rec2*2}," f" and the area of your rectangle is {length_rec*length_rec2}") else: circumference = num_check("please enter the radius of your circle: ", 1, 50) print() print(f"The circumference of your circle is {2*pi*circumference}, and the area of your circle is ") print(f"{pi*circumference**2}") print() ask_option = string_check("Would you like to re-start the code?: ", yes_no, 1) else: print() print("Thanks for using this calculator, have a good day. 😊") print("The program has ended")