import pandas # Functions go here def int_check(question, low, high): """Checks user enter an integer """ error = f"Oops - please enter a number between {low} and {high} " while True: try: response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def make_statement(statement, decoration, lines=1): """Creates headings (3 lines), subheadings (2lines) and emphasised text / mini-headings (1 line). Only use emoji for single line statements""" middle = f"{decoration * 3} {statement} {decoration * 3}" top_bottom = decoration * len(middle) if lines == 1: print(middle) elif lines == 2: print(middle) print(top_bottom) else: print(top_bottom) print(middle) print(top_bottom) # currency formatting function def currency(x): """Format numbers as currency ($#.##)""" return "${:.2f}".format(x) 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 xyz in valid_answers: # check if the response is the entire word if response == xyz or response == xyz[:num_letters]: return xyz print(f"Please choose an option from {valid_answers}") def not_blank(question): """Checks that a user response is not blank""" while True: response = input(question).strip() # remove spaces before/after if response != "": return response print("Sorry, this can't be blank, Please try again.\n") def instructions(): make_statement("Instructions", "â„šī¸") print(''' For each Customer enter ... - Their name - Their age - The payment method (cash / credit) The program will record the pizza's chosen and the size for that pizza chosen and calculate the order cost, and surcharge. Once you have either bought 5 pizza's or finished ordering, the program will display the order information and write the data to a text file (receipt). ''') def phone_check(question): while True: response = input(question) if response.isdigit() and 8 <= len(response) <= 11: return response print("Please enter a valid phone number (digits only, 8–11 digits).") # Variables MAX_PIZZA = 5 pizza_sold = 0 CREDIT_SURCHARGE = 0.023 # Delivery Fee DELIVERY_FEE = 15 # Pizza ordered list user_pizza_choice = [] user_pizza_choice_cost = [] user_size_choice = [] user_size_choice_cost = [] order_dict = { 'Item': user_pizza_choice, 'Size': user_size_choice, '|Pizza Price|': user_pizza_choice_cost, '|Size Price|': user_size_choice_cost } # pizza lists 1 pizza_items = ["Cheese", "Pepperoni", "Ham & Cheese", "BBQ", "Veggie", "Meat-lovers", "Spicy chicken", "Pesto", "Hawaiian", "Burger", ] pizza_cost = [7.50] * 10 pizza_dict_1 = { 'Pizza': pizza_items, 'Price': pizza_cost, } # pizza list 2 special_pizza = ["Desert Pizza", "Butter Chicken"] special_pizza_cost = [6.50, 8.50] pizza_dict_2 = { 'Special Pizza': special_pizza, 'Price': special_pizza_cost, } # pizza sizes pizza_size = ["Small", "Medium", "Large"] pizza_size_cost = [2.50, 3.50, 4.50] pizza_dict_3 = { 'Sizes': pizza_size, 'Price': pizza_size_cost, } # user order dict # create dataframe/s pizza_frame = pandas.DataFrame(pizza_dict_1) pizza_frame.index = pizza_frame.index + 1 pizza_frame_2 = pandas.DataFrame(pizza_dict_2) pizza_frame_2.index = pizza_frame_2.index + 1 pizza_frame_3 = pandas.DataFrame(pizza_dict_3) pizza_frame_3.index = pizza_frame_3.index + 1 # Currency Formatting (uses currency function) add_dollars = ['Price'] for var_item in add_dollars: pizza_frame[var_item] = pizza_frame[var_item].apply(currency) pizza_frame_2[var_item] = pizza_frame_2[var_item].apply(currency) pizza_frame_3[var_item] = pizza_frame_3[var_item].apply(currency) # Main routine goes here make_statement(statement="Hot Crust Co.", decoration="🍕") print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print(pizza_frame) make_statement(statement="", decoration="----") print(pizza_frame_2) make_statement(statement="", decoration="----") print(pizza_frame_3) # initialise variables / non-default options for string checker payment_ans = ('cash', 'credit') print() # ask user for their name name = not_blank("Name: ") # replace with call to 'not blank' function! # Ask for their age and check it's between 12 and 120 age = int_check("Age: ", 12, 120) # Output error message / success message if age < 12: print(f"{name} is too young") elif age > 120: print(f"{name} is too old") else: pass # Ask user for their phone number phone_number = phone_check("Phone Number: ") # ask user for payment method (cash / credit / ca / cr) pay_method = string_check("Payment method: ", payment_ans, 2) print() print(f"{name} is ordering ({pay_method})") # Ordering system # Get pizza choice while pizza_sold < MAX_PIZZA: print() typeofpizza = int_check("Would you like a general pizza or special pizza?(1 for general, 2 for special)", 1, 2) if typeofpizza == 1: print("You chose general pizza") pizza_choice = int_check("Enter pizza order number(1-10): ", 1, 10) print() print(f"-{pizza_items[pizza_choice - 1]}") user_pizza_choice.append(pizza_items[pizza_choice - 1]) user_pizza_choice_cost.append(7.5) print() pizza_sold += 1 elif typeofpizza == 2: print("You chose special pizza") pizza_choice = int_check("Enter special pizza number(1-2): ", 1, 2) print() print(f"{special_pizza[pizza_choice - 1]}") user_pizza_choice.append(special_pizza[pizza_choice - 1]) user_pizza_choice_cost.append(special_pizza_cost[pizza_choice - 1]) print() pizza_sold += 1 print() print(pizza_frame_3) print() if pizza_sold < MAX_PIZZA: size_choice = int_check("What size would you like? (1 is Small, 2 is Medium, 3 is Large)", 1, 3) print() print(f"You chose {pizza_size[size_choice - 1]} ${pizza_size_cost[size_choice - 1]}") user_size_choice.append(pizza_size[size_choice - 1]) user_size_choice_cost.append(pizza_size_cost[size_choice - 1]) print() print(f"Pizza's ordered: {pizza_sold}/{MAX_PIZZA}") print() if pizza_sold < MAX_PIZZA: want_pizza = string_check("Would you like another pizza? ") print() if want_pizza == "no": print("Your order will now be processed.") print(f"Pizza's ordered: {pizza_sold}/{MAX_PIZZA}") print(f"Your pizza's ") break else: continue if pizza_sold == MAX_PIZZA: print("You have reached the max amount of pizza!!!") # user order print() order_frame = pandas.DataFrame(order_dict) order_frame.index = order_frame.index + 1 # Currency Formatting (uses currency function) add_dollars_2 = ['|Pizza Price|', '|Size Price|'] for items in add_dollars_2: order_frame[items] = order_frame[items].apply(currency) print() print(order_frame) print() order_cost = sum(user_pizza_choice_cost + user_size_choice_cost) print(f"Cost: {currency(order_cost)}") if pay_method == "cash": surcharge = 0 total_surcharge = order_cost # if paying by credit, calculate surcharge else: surcharge = order_cost * CREDIT_SURCHARGE total_surcharge = surcharge + order_cost print(f"Total with surcharge: {currency(total_surcharge)}") print() pickup_delivery = string_check(f"Would you like pickup or delivery for your order?(pickup, delivery)", ('pickup', 'delivery'), 1) if pickup_delivery == 'pick-up': print("You have chosen pickup, your order will be here for you to pickup in 15 mins.") deliveryfee = 0 if pickup_delivery == 'delivery': delivery_address = input("You have chosen delivery, what is your delivery address?: ") deliveryfee = DELIVERY_FEE print() print(f"Address of delivery :{delivery_address}") print() # create file to hold data (add.txt extension) file_name = "Hot Crust Co" write_to = "{}.txt".format(file_name) text_file = open(write_to, "w+") # strings to write to file... heading = "=== Hot Crust Co. ===\n" customer_details = (f"Name:{name}\n" f"Age: {age}\n" f"payment method:{pay_method}\n") order_details = f"{order_frame}" price_details = f"Order Cost:{currency(total_surcharge)}" pickup_or_delivery = f"pick-up or delivery chosen: {pickup_delivery}" # list of strings... to_write = [heading, customer_details, order_details, "\n", price_details, pickup_or_delivery] # print the output... for item in to_write: print(item) # write the item to file for item in to_write: text_file.write(item) text_file.write("\n") # order confirmation print() confirmation = string_check(f"Is this your order?: ") print("Thank you, your order will now be made.")