import pandas import numpy def make_statement(statement, decoration): """Emphasises heading by adding decoration at the start and end""" print(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 'n' letter/s of a word from a list 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 first letter elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_answers}") def instructions(): make_statement("Instructions", "πŸ†”") print(''' Numbers correlate to items ''') def item_selection(): while True: try: ans = int(input("Enter item number ")) if 1 <= ans <= 5: return ans else: print("Please choose a number from the list 1-5.") except ValueError: print("That's not a valid integer. Try again.") def ask_quantity(item_name): while True: try: qty = int(input(f"How many {item_name}'s would you like? ")) if qty > 0: return qty else: print("❌ Please enter a number greater than 0.") except ValueError: print("❌ That’s not a number. Try again.") make_statement("Apu's Dairy", "🍫") print() # lists to hold ticket details all_products = ["Chocolate", "Chips", "Coke", "Lolly Bag", "Milkshake"] all_products_costs = [3.50, 2.50, 3.00, 2.00, 5.00] dairy_dict = { 'Product:': all_products, 'Price:': all_products_costs, } # create dataframe / table from dictionary dairy_frame = pandas.DataFrame(dairy_dict) dairy_frame.index = numpy.arange(1, len(dairy_frame) + 1) print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print(dairy_frame) print() # Calculate the total payable & profit for each ticket # mount_dairy_frame['Total'] = mount_dairy_frame['Product Price'] # mount_dairy_frame['Profit'] = mount_dairy_frame['Product Price'] - 1 # Work out total paid and total profit... # total_paid = mini_movie_frame['Total'].sum() # total_profit = mini_movie_frame['Profit'].sum() # print(mini_movie_frame) # print(f"Total Paid: ${total_paid:.2f}") # print(f"Total Profit: ${total_profit:.2f}") want_items = item_selection() item_name = all_products[want_items - 1] item_price = all_products_costs[want_items - 1] # now use your ask_quantity function quantity = ask_quantity(item_name) # work out cost + profit total_cost = item_price * quantity profit = (item_price - 1) * quantity