I made this project that simulates a frozen yogurt shop, where you can pick your flavor, toppings, and sauces and then pay for it. I'm a beginner at python and this is my first project. I don't even know where this idea came from - I was hungry I guess. I feel like this code is unnecessarily long and redundant though, and I would like to receive some feedback how to make this more advanced.
The first coding file is the main, the second coding file is where I put some of the functions, and the third file is a text file of the (very long) menu. The menu can be changed without affecting the code. If anyone could take the time to look at this that would be amazing.
import functions
menu_file = open("menu.txt", "r+")
menu = menu_file.readlines()
flavors = []
toppings = []
sauces = []
flavor_dictionary = {}
topping_dictionary = {}
sauce_dictionary = {}
price = 0
wants_toppings = ""
order_toppings = []
no_more_toppings = False
order_topping = 0
wants_more_toppings = False
wants_toppings_input = False
wants_sauces = ""
order_sauces = []
no_more_sauces = False
order_sauce = 0
wants_more_sauces = False
wants_sauces_input = False
# Create lists for flavors, toppings, and sauces
for i in range(menu.index("Flavors:\n")+1, menu.index("Toppings:\n")-1):
flavors.append(menu[i].rstrip("\n"))
flavor_dictionary[i] = flavors[i - 1]
for i in range(menu.index("Toppings:\n")+1, menu.index("Sauces:\n")-1):
toppings.append(menu[i].rstrip("\n"))
topping_dictionary[(i - menu.index("Toppings:\n"))] = toppings[(i - menu.index("Toppings:\n")) - 1]
for i in range(menu.index("Sauces:\n")+1, menu.index(menu[-1])+1):
sauces.append(menu[i].rstrip("\n"))
sauce_dictionary[(i - menu.index("Sauces:\n"))] = sauces[(i - menu.index("Sauces:\n")) - 1]
menu_file.close()
# Ask customer if they want to order
print("\n✧༺♥༻∞ Welcome to Sweet Frost Frozen Yogurt Shop ∞༺♥༻✧")
wants_to_order = input("Would you like to place an order? [Yes/No] ")
asking = True
while asking:
if wants_to_order.upper() == "YES" or wants_to_order.upper() == "Y":
ordering = True
break
elif wants_to_order.upper() == "NO" or wants_to_order.upper() == "N":
ordering = False
paying = False
break
elif wants_to_order.upper() != "YES" and wants_to_order.upper() != "Y" and wants_to_order.upper() != "NO" and wants_to_order.upper() != "N":
print("Invalid input")
wants_to_order = input("Would you like to place an order? [Yes/No] ")
continue
# Take size of order
while ordering:
order_size = input("\nWhat size cup would you like?\n[a] Small - $3.00\n[b] Medium - $4.00\n[c] Large - $6.00\n")
while (order_size.lower() != "a" and order_size.lower() != "b" and order_size.lower() != "c"):
print("Invalid input")
order_size = input("What size cup would you like?\n[a] Small\n[b] Medium\n[c] Large\n")
if order_size.lower() == "a":
size = "Small"
price = price + 3.00
elif order_size.lower() == "b":
size = "Medium"
price = price + 4.00
elif order_size.lower() == "c":
size = "Large"
price = price + 6.00
# Take flavor of order
print("What flavor would you like for your " + size.lower() + " frozen yogurt?")
for i in range(len(flavors)):
print("[" + str(i+1) + "] " + flavors[i])
order_flavor = input()
while order_flavor.isdigit() == False or int(order_flavor) == 0 or int(order_flavor) > len(flavors):
print("Invalid input\nWhat flavor would you like for your " + size.lower() + " frozen yogurt? ")
order_flavor = input()
# Take toppings and sauces of order
if order_flavor.isdigit() == True and int(order_flavor) <= len(flavors) and int(order_flavor) > 0:
functions.run_choices("topping", toppings, size, flavor_dictionary, topping_dictionary, order_flavor, wants_toppings, order_toppings, no_more_toppings, order_topping, wants_more_toppings)
functions.choices("topping", toppings, size, flavor_dictionary, topping_dictionary, order_flavor, wants_toppings, order_toppings, no_more_toppings, order_topping, wants_more_toppings, wants_toppings_input)
functions.run_choices("sauce", sauces, size, flavor_dictionary, sauce_dictionary, order_flavor, wants_sauces, order_sauces, no_more_sauces, order_sauce, wants_more_sauces)
functions.choices("sauce", sauces, size, flavor_dictionary, sauce_dictionary, order_flavor, wants_sauces, order_sauces, no_more_sauces, order_sauce, wants_more_sauces, wants_sauces_input)
# Ask customer if they want to make another purchase
wants_to_order = input("Would you like to make another purchase? [Yes/No] ")
if wants_to_order.upper() != "YES" and wants_to_order.upper() != "Y" and wants_to_order.upper() != "NO" and wants_to_order.upper() != "N":
valid_order_input = False
while valid_order_input != True:
print("Invalid input")
wants_to_order = input("Would you like to place an order? [Yes/No] ")
elif wants_to_order.upper() == "YES" or wants_to_order.upper() == "Y":
ordering = True
paying = False
elif wants_to_order.upper() == "NO" or wants_to_order.upper() == "N":
ordering = False
paying = True
# Take payment from customer
while paying:
print("\nThank you for your purchase at Sweet Frost Yogurt Shop! Your total is $" + str(price) + "0")
cash_amount = input("Please enter your cash amount: $")
converted_cash_amount = functions.check_cash(cash_amount)
# Customer overpaid or paid exact amount
if converted_cash_amount >= price:
change = "{:.2f}".format(converted_cash_amount - price)
print("Your change is $" + change)
break
# Customer underpaid
elif converted_cash_amount < price:
enough_cash = False
while not enough_cash:
amount_owed = price - converted_cash_amount
formatted_amount_owed = "{:.2f}".format(amount_owed)
cash_amount = input("You still owe $" + formatted_amount_owed + ". Please enter your remaining cash amount: $")
converted_cash_amount = functions.check_cash(cash_amount)
if converted_cash_amount >= amount_owed:
change = converted_cash_amount - amount_owed
formatted_change = "{:.2f}".format(change)
print("Your change is $" + formatted_change)
enough_cash = True
paying = False
elif converted_cash_amount < float(amount_owed):
price = float(amount_owed)
enough_cash = False
continue
print("✧༺♥༻∞ Thanks for stopping by! ∞༺♥༻✧")
# Print out list of toppings and sauces
def run_choices(type, list_of_type, size, flavor_dictionary, type_dictionary, order_flavor, wants_type, order_types, no_more_types, order_type, wants_more_type):
print("\nCheck out our " + type + " menu:")
for i in range(len(list_of_type)):
print("[" + str(i + 1) + "] " + list_of_type[i])
# Get the toppings and sauces the customer wants
def choices(type, list_of_type, size, flavor_dictionary, type_dictionary, order_flavor, wants_type, order_types, no_more_types, order_type, wants_more_type, wants_type_input):
wants_type = input("Would you like to add any " + type + "s" + " to your " + size.lower() + " " + flavor_dictionary[int(order_flavor)].lower() + " frozen yogurt? [Yes/No] ")
while wants_type_input == False:
if wants_type.upper() == "NO" or wants_type.upper() == "N":
wants_type_input = True
elif wants_type.upper() == "YES" or wants_type.upper() == "Y":
order_types = []
no_more_types = False
while no_more_types != True:
print("What " + type + " would you like?")
order_type = input()
while order_type.isdigit() == False or int(order_type) == 0 or int(order_type) > len(list_of_type):
print("Invalid input\nWhat " + type + " would you like?")
order_type = input()
if order_type.isdigit() == True and int(order_type) <= len(list_of_type) and int(order_type) > 0:
order_types.append(order_type)
wants_more_type = input("Would you like to add another " + type + "? [Yes/No] ")
if wants_more_type.upper() == "NO" or wants_more_type.upper() == "N":
print("Your " + flavor_dictionary[
int(order_flavor)].lower() + " frozen yogurt will have the following " + type + "s: ")
for i in range(len(order_types)):
order_types[i] = type_dictionary[int(order_types[i])]
print(order_types)
no_more_types = True
wants_type_input = True
elif wants_more_type.upper() == "YES" or wants_more_type.upper() == "Y":
no_more_types = False
elif wants_type.upper() != "YES" and wants_type.upper() != "Y" and wants_type.upper() != "NO" and wants_type.upper() != "N":
print("Invalid input")
wants_type = input(
"Would you like to add any " + type + "s" + " to your " + size.lower() + " " + flavor_dictionary[
int(order_flavor)].lower() + " frozen yogurt? [Yes/No] ")
if wants_type.upper() == "NO" or wants_type.upper() == "N":
break
if wants_type.upper() == "Yes" or wants_type.upper() == "Y":
wants_type_input = False
# Check if cash input is valid
def check_cash(cash_amount):
accept_cash = False
while not accept_cash:
try:
converted_cash_amount = float(cash_amount)
accept_cash = True
except ValueError:
print("Invalid input")
cash_amount = input("Please enter your cash amount: $")
accept_cash = False
converted_cash_amount = float(cash_amount)
return converted_cash_amount
Flavors:
Banana
Blueberry
Blue raspberry
Brownie batter
Bubblegum
Butter pecan
Cake batter
Carrot cake
Cheesecake
Chocolate
Coconut
Coffee
Cookie dough
Cookies and cream
Cotton candy
Dulce de leche
French vanilla
Green apple
Honey dew
Lemon
Mango
Mint chocolate chip
Orange creamsicle
Peach
Peanut butter
Peppermint candy cane
Pistachio
Pumpkin pie
Red velvet
S'mores
Snickerdoodle
Strawberry
Strawberry banana
Strawberry kiwi
Vanilla
Watermelon
Toppings:
Almonds
Andes chocolate mints
Bananas
Blueberries
Brownie bites
Cheesecake bites
Chocolate chips
Cinnamon Toast Crunch
Coconut shavings
Cookie dough bites
Frosted animal crackers
Fruity Pebbles
Graham crackers
Granola
Gummy bears
Jelly beans
Kit Kat
Kiwi
M&M's
Marshmallows
Oreo crumbs
Peanut butter chips
Peanuts
Pecans
Pineapple
Reese's peanut butter cups
Reese's Pieces
Pretzels
Pumpkin pie bites
Rainbow sprinkles
Snickers
Strawberries
Waffle cone
Walnuts
White chocolate chips
Sauces:
Butterscotch sauce
Caramel sauce
Chocolate syrup
Honey
Marshmallow cream
Peanut butter sauce
Strawberry syrup
Whipped cream
White chocolate syrup