import pandas 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) def not_blank(question): """checks that the users reponce is not blank""" while True: response = input(question) if response !="": return response print("Sorry, this cant be blank. please try again.\n") 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}") # currency formatting function def currency (x): return "${:.2f}".format(x) #main routine gose here #intialise variables / non-default options for string checker payment_ans = ('cash', 'credit') #price list CHILD_PRICE = 7.50 ADULT_PRICE = 10.50 SENIOR_PRICE = 6.50 #SERPLUS (5%) CREDIT_SURCHARGE=0.05 #lists to hold ticket details all_names = [] all_ticket_cost = [] all_surcharges = [] mini_moive_dict = { 'Name': all_names, 'Ticket Price': all_ticket_cost, 'Surcharge': all_surcharges } # loop for testing while True: print() name= not_blank("name: ") if name =="xxx": break age = int_check("Age: ", 12,120) if age <12: print(f"{name} is too young") continue elif age<16: ticket_price=CHILD_PRICE elif age <65: ticket_price = ADULT_PRICE elif age <121: ticket_price = SENIOR_PRICE else: print(f"{name} is to old") continue pay_method = string_check("payment ,method:", payment_ans, 2) if pay_method == "cash": surcharge = 0 else: surcharge= ticket_price*CREDIT_SURCHARGE all_names.append(name) all_ticket_cost.append(ticket_price) all_surcharges.append(surcharge) mini_movie_frame = pandas.DataFrame(mini_moive_dict) mini_movie_frame['Total'] = mini_movie_frame['Ticket Price'] + mini_movie_frame['Surcharge'] mini_movie_frame['Profit'] = mini_movie_frame['Ticket Price'] - 5 total_paid = mini_movie_frame['Total'].sum() total_profit = mini_movie_frame['Profit'].sum() add_dollars = ['Ticket Price', 'Surcharge','Total','Profit'] for var_item in add_dollars: mini_movie_frame[var_item] = mini_movie_frame[var_item].apply(currency) print(mini_movie_frame.to_string(index=False)) print() print(f"total paid ${total_paid:.2f}") print(f"total profit {total_profit:.2f}")