import math import random 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("list of shapes:'circle', 'square', 'triagle','rectangle',and 'xxx' to break the loop and end the code ") print( "second please enter the dimentions of the shape these must be bellow 20000") print( "then follow the steps again if you need to find the area of another shape") print("if you wish to exit you can enter xxx and the program will end ") print( "this will also show you all the shapes you have put in with the answers ") print() make_statement("important please read","***") print() print("PLEASE MAKE SURE THAT ALL MESURMENTS ARE IN THE SAME LENGTH ") print("eg: all must be in meter") def num_check(question, low, high): """Checks user enters a number (integer or float) between low and high inclusive.""" error = f"Oops - please enter a number between {low} and {high}." while True: try: response = float(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) going = 1 #heading make_statement("area and perimeter caulator", "📏") print() # ask if instructions are needed 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 shape = string_check_shape("enter the shape you want to find: ") print() #if name is exit code break out of loop if shape == "xxx": break #if it is a square if shape == "square" : print("you have chosen square") print() #finding out lengths length_1 = num_check("what is length of the sides:",1,20000) #find area area = length_1*length_1 #find perimeter perimeter = length_1*4 if shape == "triagle": # finding out lengths print("you have chosen triangle ") print() length_1 = num_check("what is the base of the triangle:", 1, 20000) height_1 = num_check("what is the height of the triangle:", 1, 20000) # find area area = 0.5*length_1*height_1 hypotenuse_squared= length_1*length_1+height_1*height_1 hypotenuse = math.sqrt(hypotenuse_squared) # find perimeter perimeter = length_1+height_1+hypotenuse if shape == "circle": print("you have chosen circle ") print() # finding out length of radius radius = num_check("what is the radius of the circle:",1,20000) # find area area = pi_value * (radius ** 2) # find perimeter perimeter = 2 * pi_value * radius if shape == "rectangle": print("you have chosen rectangle ") print() # finding out lengths length_1 = num_check("what is the length of the rectangle:",1,20000) height_1 = num_check("what is the height of the rectangle:", 1, 20000) # find area area = length_1 * height_1 # find perimeter 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) shape_show_all = pandas.DataFrame(mini_moive_dict) shape_show_all['shape'] shape_show_all['area'] shape_show_all['perimeter'] print(shape_show_all)