def make_statement(statement, decoration): print(f"{decoration * 3} {statement} {decoration * 3}") def string_check(question, valid_ans_list=('yes', 'no'), num_letters=1): 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 {valid_ans_list}") def instructions(): make_statement(statement="Instructions", decoration="ℹ️") print(''' For each ticket holder enter ... - Their name - Their age - The payment method (cash / credit) The program will record the ticket sale and calculate the ticket cost (and the profit). Once you have either sold all of the tickets or entered the exit code ('xxx'), the program will display the ticket sales information and write the data to a text file. It will also choose one lucky ticket holder who wins the draw (their ticket is free). ''') def not_blank(question): while True: response = input(question).strip() if response != "": return response print("Sorry, this can't be blank. Please try again.\n") def int_check(question): error = "Oops - please enter an integer." while True: try: response = int(input(question)) return response except ValueError: print(error) # MAIN PROGRAM STARTS HERE Max_ticket = 5 tickets_sold = 0 payment_ans = ('cash', 'credit') make_statement(statement="Mino Movie Fundraiser Program", decoration="🍿") print() want_intro = string_check("Do you want to see the instructions? ") if want_intro == "yes": instructions() print() while tickets_sold < Max_ticket: print() name = not_blank("Name: ") if name == "xxx": break age = int_check("Age: ") if age < 12: print("Sorry you are too young for this movie") continue elif age > 120: print(f"{name} is too old.") continue pay_method = string_check("Payment method (cash/credit): ", payment_ans, num_letters=2) print(f"{name} has bought a ticket ({pay_method}).") tickets_sold += 1 if tickets_sold == Max_ticket: print(f"You have sold all the tickets (ie: {Max_ticket} tickets") else: print(f"You have sold {tickets_sold} / {Max_ticket} tickets.")