import math import pandas pi_value = math.pi def make_statement(statement , decoration): """emphasises headings by adding decoration""" print(f"{decoration * 3} {statement} {decoration * 3}") def string_check(question, valid_ans_list=('yes', 'no'), num_letter=1): """checks the users enter the full word or the first letter of a word from a list of responces""" while True: response = input(question).lower() for item in valid_ans_list: #checks if the response is the entire word if response == item: return item #checks if the responce is the first letter elif response == item [:num_letter]: return item print(f"please choose an option from {valid_ans_list}") def string_check_shape(question, valid_ans_list=('circle', 'square', 'triagle','rectangle','xxx'), num_letter=1): """checks the users enter the full word or the first letter of a word from a list of responces""" while True: response = input(question).lower() for item in valid_ans_list: #checks if the response is the entire word if response == item: return item #checks if the responce is the first letter elif response == item [:num_letter]: return item print(f"please choose an option from {valid_ans_list}") def instructions(): make_statement("instuctions", "***") print(" first select a shape that you want to find the area of.") print( "second please enter the dimentions of the shape ") print( "then follow the steps again if you need to find the area of another shape") def int_check(question, low , high): """checks user enter an integer / foat that is more than zero""" error = f"opps - please enter an interger between {low} and {high}." while True: try: # changing the responce to an integer and check that it is more than 0 response = int (input(question)) if low <= response <= high: return response else: print(error) except ValueError: print (error) going = 1 make_statement("area caulator", "📏") print() want_insturctions = string_check("do you want to see the instuctions?") if want_insturctions == "yes": instructions() print() #lists to hold ticket details all_shape = [] all_area = [] all_perimeter = [] mini_moive_dict = { 'shape': all_shape , 'area': all_area, 'perimeter': all_perimeter } #loop area and perimiter questions while going > 0 : #find out what shape you want to find the area of shape = string_check_shape("enter the shape you want to find: ") print() #if shape is exit code break out of loop if shape == "xxx": break #caulate the area of the chosen shape if shape == "square": length_1 = int_check("what is length of the sides:",-1,10000) area = length_1*length_1 perimeter = length_1*4 if shape == "triagle": length_1 = int_check("what is the base of the triangle:", -1, 10000) height_1 = int_check("what is the height of the triangle:", -1, 10000) area = 0.5*length_1*height_1 hypotenuse_squared = length_1*length_1+height_1*height_1 hypotenuse = math.sqrt(hypotenuse_squared) perimeter = length_1+height_1+hypotenuse if shape == "circle": radius = int_check("what is the radius of the circle:",-1,1000000) area = pi_value * (radius ** 2) perimeter = 2 * pi_value * radius if shape == "rectangle": length_1 = int_check("what is the length of the rectangle:",-1,1000000) height_1 = int_check("what is the height of the rectangle:", -1, 10000) area = length_1 * height_1 perimeter = (length_1 * 2) + (height_1*2) print(f"the area is {area}") print(f"the perimeter{perimeter}") all_shape.append(shape) all_area.append(area) all_perimeter.append(perimeter) mini_movie_frame = pandas.DataFrame(mini_moive_dict) mini_movie_frame['shape'] mini_movie_frame['area'] mini_movie_frame['perimeter'] print(mini_movie_frame)