# Lists to hold ticket details import pandas import numpy # Functions go here def make_statement(statement, decoration): """Emphasises headings by adding decoration at the start and end""" return f"{decoration * 3} {statement} {decoration * 3}" def string_check(question, valid_answers=('yes', 'no'), num_letters=1): """Checks that users enter the full word or the first letter of a word from alist of valid responses""" while True: response = input(question).lower() for item in valid_answers: # check if the response is the entire word if response == item: return item # check if it's the 'n' letter elif response == item[:num_letters]: return item def instructions(): make_statement("Instructions", "ℹ️") 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): """Check that a user response is not blank""" while True: response = input(question) if response != "": return response print("Sorry, this can't be blank. Please try again.\n") def int_check(question, low, high): """Checks users enter an integer""" error = f"Oops - please enter a number between {low} and {high}" while True: try: # Return the response if it's an integer response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def currency(x): """Formats numbers as currency (s#.###)""" return "${:.2f}".format(x) # Main Routine goes here # Initialise ticket numbers MAX_TICKETS = 5 tickets_sold = 0 # Program main heading print(make_statement("Entering the theatre Program", "🍿")) print() print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print() # initialise variables / non-default options for string checker payment_ans = ['cash', 'credit'] # Ticket Price List CHILD_PRICE = 10 TEEN_PRICE = 19 ADULT_PRICE = 25 SENIOR_PRICE = 20 print() # What movie are you choosing to watch? all_names = ["Minecraft", "Spiderman", "Chucky", "Fallout", "Star Wars", "Meg", "Jurassic World"] all_ticket_costs = [13, 12, 17, 14, 15, 21, 18,] all_age_ratings = ["PG", "PG", "R", "M", "PG", "R", "M"] mini_movie_dict = { 'Name': all_names, '$Ticket Price': all_ticket_costs, 'Age ristriction': all_age_ratings, } # Lists to hold user details all_user_names = [] all_user_movies = [] all_user_food = [] all_user_prices = [] all_user_prices_dict = { 'Name': all_user_names, 'Movie': all_user_movies, 'Ticket Price': all_user_prices, } # any snacks you're willing to have before the movie starts? all_food = ["Popcorn", "Chips", "Candy", "Ice cream", "Pizza", "Fries", "Chocolate",] all_food_costs = [7, 8, 5, 11, 14, 13, 6] all_drinks = ["Water", "Coke", "Pepsi", "Sprite", "Juice", "Wine", "Beer"] all_drink_costs = [3, 2, 2, 4, 3, 9, 12] all_user_food_dict = { 'Food': all_food, 'Food prices': all_food_costs, 'Drinks': all_drinks, 'Drink Prices': all_drink_costs, } order_frame = pandas.DataFrame(mini_movie_dict) food_frame = pandas.DataFrame(all_user_food_dict) order_frame.index = numpy.arange(1, len(order_frame) + 1) print(order_frame) print() movie_choice = int_check("Pick a number between of 1-7 depending of what movie you're choosing ", 1, 7) movie = all_names[movie_choice-1] # Display the selected movie print(f"You selected {movie}") # Ask how many tickets to buy user_tickets = int_check("How many tickets do you want to purchase? ", 1, 5) # choose_a_movie_list = [1,2,3,4,5,6,7] print() payment_ans = ('cash', 'credit') print() for tickets in range(user_tickets): # ask user for their name (and check it's not blank) print() name = not_blank("Name: ") # if name is exit code, break out of loop if name == "xxx": break # Ask for their age and check it's between 12 and 120 age = int_check("how old are you?: ", 13, 80) # Output error message / success message # Child ticket is $10.00 if age <= 15: ticket_price = CHILD_PRICE print("Then you are watching PG movies") # Teenage ticket is ($19.00) elif age <= 21: ticket_price = TEEN_PRICE print("Then you are watching PG and M movies") # Adult Citizen ticket ($25.00) elif age <= 64: ticket_price = ADULT_PRICE print("Then you are watching PG and M and R movies") # Senior Citizen ticket ($20.00) else: ticket_price = SENIOR_PRICE print(f"{name} gets a senior ticket price") print(f"{name} has bought a ${ticket_price} ticket") buy_food = string_check("Would you like to buy food & drinks? ",) if buy_food == 'yes': food_frame.index = numpy.arange(1, len(food_frame) + 1) print(food_frame) print() # add name, ticket cost and movie all_user_names.append(name) all_user_movies.append(movie) # all_user_food.append(food) all_user_prices.append(ticket_price) # display user order details # user_order_frame = pandas.DataFrame(all_user_prices_dict) print(user_order_frame) ticket_total = sum(all_user_prices) print(f'Total: ${ticket_total}') print() pay_method = string_check("Payment method (cash or credit) ", payment_ans, 2) if pay_method == 'credit' or pay_method == 'cr': charge = (ticket_total * 2.5) /100 cost_charge = round(ticket_total + charge, 2 ) print(f" Surcharge = ${charge} Total cost = ${cost_charge}" ) else: print(f" Total cost = ${ticket_total}")