Last active
March 21, 2021 21:47
-
-
Save CyberFlameGO/bf5af658e50e9dd4b39c0edcb94d2fb7 to your computer and use it in GitHub Desktop.
A school task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# From https://github.com/CyberFlameGO/schoolPythonProject/blob/master/coffee.py | |
# This dictionary stores the coffees available and their prices | |
coffee_kv_store = {"espresso": 2.50, "mocha": 4, "cappuccino": 3, "latte": 3.50, "flat white": 2.50, "long black": 2.50} | |
# This list stores the coffees ordered | |
coffees_ordered = [] # a key-value pair would be ideal but this is easiest imo tbh | |
# 'while' loop variables | |
ordering = True | |
order_fetching = True | |
quantity_fetching = True | |
# declares a variable for use in the calculation section. i could've declared it just before the 'for' loop but this looks tidier | |
total_calc = 0 | |
# contains all ordering code | |
while ordering: | |
# fetches the type of coffee the user wants to order, checks if it matches anything in my dictionary, and if so, | |
# allows the user to continue | |
while order_fetching: | |
# maybe if i had more time, i'd print the list of coffees available | |
ui_coffee_order = input("What species of coffee would you like to order?\n").strip().lower() | |
if ui_coffee_order in coffee_kv_store: | |
order_fetching = False | |
coffees_ordered.append(ui_coffee_order) | |
# just a lil easter egg if people have such a big brain to type this | |
elif ui_coffee_order == "coffee": | |
print("Yes, what type of coffee?") | |
else: | |
print("We don't have that, try again!") | |
# asks the user how many coffees (of type entered in ui_coffee_order's input) they'd like | |
while quantity_fetching: | |
try: | |
quantity = int(input("How many {}s do you want?\n".format(coffees_ordered[-1].title()))) | |
if quantity >= 1: | |
quantity_fetching = False | |
else: | |
print("Your input must be greater than or equal to '1', try again!") | |
except ValueError: | |
print("Invalid input! Try again with a whole number please!") | |
# adds 'ui_coffee_order' in the quantity from 'quantity' to the list | |
for coffees in range(1, quantity): | |
coffees_ordered.append(ui_coffee_order) | |
# asks the user if they want to order more coffee | |
add_order_bool = input( | |
"Do you want to order more coffee?\n" | |
"Type 'y' for yes, and anything else to continue to checkout:\n").strip().lower() | |
# if anything other than 'y', continues to checkout (calculations) | |
if add_order_bool != "y": | |
ordering = False | |
# if 'y', re-enables loop variables and restarts the `ordering` loop | |
else: | |
order_fetching = True | |
quantity_fetching = True | |
# calculations section | |
# this is the quickest and most simple way to put the total price into a variable. this was a quick fix to a bug, | |
# all done in the nano text editor haha | |
for coffee in coffees_ordered: | |
total_calc = total_calc + coffee_kv_store.get(coffee) | |
# if there's more than one item in the list, just says "Those coffees will cost you $x!" | |
if len(coffees_ordered) > 1: | |
print("Those coffees will cost you ${}!".format(total_calc)) | |
# if there's only one item in the list (including duplicates), tells you what you ordered and the price | |
elif len(coffees_ordered) == 1: | |
print("That {} will cost you ${}!".format(ui_coffee_order.title(), coffee_kv_store.get(ui_coffee_order))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment