# 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 = 21 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 restriction': all_age_ratings, } # Lists to hold user details all_user_names = [] all_user_movies = [] all_user_ticket_prices = [] all_user_food = [] all_user_food_prices = [] all_food_package = [] all_food_packages_costs = [] # any snacks you're willing to have before the movie starts? all_food = ["Popcorn🍿", "Chips🧀", "Candy🍬", "Ice cream🍦", "Pizza🍕", "Fries🍟", "Chocolate🍫", "Water💧", "Coke🥤", "Pepsi🥤", "Sprite🍋", "Juice🧃", "Popcorn🍿 + Ice cream🍦", "Chips🧀 + Coke🥤", "Pizza🍕 + Pepsi🥤", "Fries🍟 + Water💧", "Candy🍬 + Sprite🍋", "Chocolate🍫 + Juice🧃"] all_food_costs = [7, 8, 5, 11, 14, 13, 6, 3, 2, 2, 4, 3, 18, 10, 16, 16, 9, 9] all_user_prices_dict = { 'Name': all_user_names, 'Movie': all_user_movies, 'Ticket Price': all_user_ticket_prices, 'Food & Drinks': all_user_food, 'Prices': all_user_food_prices } all_user_food_dict = { 'Food & Drinks': all_food, 'Prices': all_food_costs, } order_frame = pandas.DataFrame(mini_movie_dict) ticket_frame = pandas.DataFrame(all_user_prices_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) # Add the number of movies to the user list using the number of tickets for movies in range(user_tickets): all_user_movies.append(movie) # 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: ") all_user_names.append(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) if age <= 12: print("Sorry, but you're too young to watch") # 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 <= 19: ticket_price = TEEN_PRICE print("Then you are watching PG and M movies") # Adult Citizen ticket ($21.00) elif age <= 21: 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") # add ticket cost all_user_ticket_prices.append(ticket_price) 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() # Ask which food or drink to buy # Ask how many foods to order user_food_drink = int_check("Which food or drink? ", 1, 18) food = all_food[user_food_drink-1] food_price = all_food_costs[user_food_drink - 1] # Display the message print(f"You selected {food} ${food_price}") else: food = "No food" food_price = 0.0 # Display the message print(f"You did not select any food") # add food etc all_user_food.append(food) all_user_food_prices.append(food_price) # display user order details user_order_frame = pandas.DataFrame (all_user_prices_dict) user_food_frame = pandas.DataFrame (all_user_food_dict) print(user_order_frame) ticket_total = sum(all_user_ticket_prices) print(f'Total ticket prices: ${ticket_total}') food_total = sum(all_user_food_prices) total_food_ticket = ticket_total + food_total print(f'Total food prices: ${food_total}') print() print(f'All total prices: ${total_food_ticket}') print() pay_method = string_check("Payment method (cash or credit) ", payment_ans, 2) if pay_method == 'credit' or pay_method == 'cr': charge = (total_food_ticket * 2.5) /100 cost_charge = round(total_food_ticket + charge, 2 ) print(f" Surcharge = ${charge} Total cost = ${cost_charge}" ) else: print(f" Total cost = ${total_food_ticket}") print() print(f"The program has ended")