Beginner programmer, functions not working
beginner here, im currently creating a coffee shop program in pycharm where the costumer inputs the product and then the program sums up all of the price. Im trying to loop the program with the use of functions so the customer can order a many as they want. But when i inputted def main(): in the program, the program under the function does not continue when i run it and i made sure that the codes under the function are indented. Any help would be appreciated thanks enter image description here
here's the code, sorry
print("Good day!, welcome to Avenida's coffee shop")
print("Before i take you order, may i know your name?")
name = input("Input name here: ")
print(
"Hello there " + name + "!, to get started we sell different kinds of food here, we sell coffee, frappe, cake, and pastas")
print("To access our menu, input your preferred food below")
def main():
total_price = 0
category = input("Input your preferred food here: ")
if category.lower() == "coffee":
print("Coffee Menu:")
print("1 Cappuccino = $2")
print("2 Espresso = $2.50")
print("3 Latte = $3")
coffee_input = input("Input the assigned number of the coffee that you would like to order: ")
if int(coffee_input) == 1:
print("How many cappuccino would you like to order?")
coffee_quantity = input("Input here: ")
coffee_total = float(coffee_quantity) * 2
print("That would be $" + str(coffee_total))
total_price = total_price + coffee_total
if int(coffee_input) == 2:
print("How many espresso would you like to order?")
coffee_quantity = input("Input here: ")
coffee_total = float(coffee_quantity) * 2.50
print("That would be $" + str(coffee_total))
total_price = total_price + coffee_total
if int(coffee_input) == 3:
print("How many latte would you like to order?")
coffee_quantity = input("Input here: ")
coffee_total = float(coffee_quantity) * 3
print("That would be $" + str(coffee_total))
total_price = total_price + coffee_total
Try adding this to the end of your code, outside of your main
loop. You defined a function called main
, but you did not execute it, thus the issue.
if __name__ == '__main__':
main()