How do I get or initialize the variable that I want? - python

I'm trying to write a simple program, but I meet a problem that the program does not output the given variable "tax" in the end.
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
tax = total*0.06
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()

when you initialized tax, you gave it a value of 0 because total*0.06 at that point equaled zero.
python goes line by line so the variable "tax" didn't change its value for the whole code, you only changed "total".
so to get the tax, you should calculate it again.
print("Current total: $",total)
tax=0.06*total
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")

Here the value of total gets updated but the tax is calculated before the check as given below, hence tax will output tax = total*0.06 where initially total=0
Please try this:
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = tax = 0
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
tax = total*0.06
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()

I guess your problem is solved.Also start using python dictionary instead of using lots of if else statements
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
tax = total*0.06
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
price_dict = {
1: menu1,
2: menu2,
3: menu3,
4: menu4
}
if 0 < choose < 5:
total += price_dict[choose]
else:
if choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
tax = total*0.06
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()

Now your tax is always 0. You have to calculate the tax at the end. Like this:
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $", total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
print("Current total: $", total)
tax = total * 0.06
print("Sales tax: $", tax)
print("Total Bill: $", total + tax)
print("Have a nice day!")
main()

Related

Expected expression ATM

I was following along with a youtube video to a ATM using python and I got expected expression. I dont know how to fix it. line 32, 37 and 40.
enter image description here
You can't have an elif after an else. This is because else will capture all the remaining cases. Indentation, meaning spaces or tabs before the line is very important in Python.
Here is what I think you meant to write:
balance = 1000
print("""
Welcome to Dutch Bank
Choose Transaction
1) BALANCE
2) WITHDRAW
3) DEPOSIT
4) EXIT
""")
while True:
option = int(input("Enter Transaction"))
if option == 1:
print ("Your Balance is", balance)
anothertrans = input("Do You Want to make another Transaction? Yes/No: ")
if anothertrans == "YES":
continue
else:
break
elif option == 2:
withdraw = float(input("Enter Amount To Withdraw"))
if (balance > withdraw):
total = balance - withdraw
print("Success")
print("Your New Balance is: ",total)
else:
print("Insufficient Balance")
elif option == 3:
deposit = float(input("Enter Amount To Deposit"))
totalbalance = balance + deposit
print("Sucess")
print("Total Balance Now is: ", totalbalance)
elif option == 4:
print("Thank You ForBanking With Dutch Bank")
exit()
else:
print ("No selected Transaction")

How can I add ticket variable and discount variable to calculate total trip cost?

# The options for where the user wants to go.
options = str(input("Where would you like to go? "))
if options == "Hawaii":
print("You have selected: Hawaii")
elif options == "hawaii":
print("You have selected: Hawaii")
elif options == "bahamas":
print("You have selected: The Bahamas")
elif options == "Bahamas":
print("You have selected: The Bahamas")
else:
print("Avaliable locations are: Hawaii or the Bahamas.")
ticket_price = 2300
discount = 0
# The airlines that are available to the user.
print("1. Us Air")
print("2. Delta")
airline = str(input("Which airline would you like to choose? "))
if airline == 1:
print("You have selected US Air")
elif airline == 2:
print("You have selected Delta Airways")
else:
print("There are no available airlines at this moment")
# Here is where how many tickets are needed based on how many people are going on the flight.
passengers = int(input("How many people are joining for this flight? "))
if passengers == 1:
print("You have selected one passenger.")
elif passengers == 2:
print("You have selected two passengers.")
elif passengers == 3:
print("You have selected three passengers.")
else:
print("Maximum number of passengers for a single order is 3.")
# Here is the chance that you or someone is your group is under the age of 18, and can qualify for a 25% discount.
discount = str(input("Are you or any passengers under the age of 18? "))
if discount == "Yes":
print("Congrats you qualify for a 25% discount!")
elif discount == "yes":
print("If so how many?")
int(input(""))
print("Congrats you qualify for a 25% discount!")
else:
print("Confirmed, no one is under the age of 18")
ticket_cost = (ticket_price*discount* 0.25)
After getting all the information, you may compute the total price
ticket_cost = passengers * ticket_price
Taking into acount the under 18 part :
discount = input("Are you or any passengers under the age of 18? ")
passengers_under_18 = 0
if discount.lower() == "yes":
print("Congrats you qualify for a 25% discount!")
passengers_under_18 = int(input("If so how many?"))
else:
print("Confirmed, no one is under the age of 18")
ticket_cost = (passengers - passengers_under_18) * ticket_price + passengers_under_18 * ticket_price * 0.25

The price doesn't add up

creating a pizza ordering program for IT class, almost finished with it but I'm currently stuck with a problem that I can't seem to fix or don't know how to. As the user is finished choosing their pizza it was suppose to add up the total cost of the pizza they have chosen but the problems is they don't add up the instead the price stays the same
Name:Jack
Telephone:47347842
ORDER:
['2. Hawaiian pizza', 8.5]
['1. Pepperoni pizza', 8.5]
['3. Garlic cheese pizza (with choice of sauce)', 8.5]
Total Price: 8.50
Here's the price list that they have to choose from
['1. Pepperoni pizza', 8.5]
['2. Hawaiian pizza', 8.5]
['3. Garlic cheese pizza (with choice of sauce)', 8.5]
['4. Cheese pizza (with choice of sauce)', 8.5]
['5. Ham and cheese pizza', 8.5]
['6. Beef & onion pizza', 8.5]
['7. Vegetarian pizza', 8.5]
['8. BBQ chicken & bacon aioli pizza', 13.5]
['9. Boneless pizza (italian style anchovy with no bones)', 13.5]
['10. Pizza margherita', 13.5]
['11. Meat-lover’s pizza', 13.5]
['12. Tandoori pizza', 13.5]
I don't know if the problems lies in this code but it seem like it is. I originally I tried using 'cost.append' but it only came up with an error like this
unsupported operand type(s) for +: 'int' and 'str'
def Choice_of_pizza():
for i in range(1,pizza_no
+1): #Repeats a number of times (number user has inputted)
while True:
try: #Validating inputs
pizza_kind = int(input("Choice of pizza(s):"))
if pizza_kind < 1:
print("Refer to PIZZA MENU for number order")
continue
if pizza_kind > 12:
print("Refer to PIZZA MENU for number order")
continue
else:
pizza = pizza_kind - 1 #Makes the list start at 1
cost.append(MENU[pizza_kind-1][0][pizza])
customerOrder.append(MENU[pizza_kind-1][pizza])
global total_cost
total_cost = sum(cost) #Sum of the pizzas
global Combined_Total
if delivery == "D": #Adds $3 dollars to the total cost if delivery
Combined_Total = total_cost + Delivery_cost
else: #Price stays the same if pick up
Combined_Total = total_cost
break
except ValueError:#Validating inputs - accepts only numbers and can't be left blank
print("Please use numbers only")
continue
Choice_of_pizza()
So I went and replace it with 'cost=+customerOrder[i][1]' but even then it somewhat works with the names of the pizza being added but not the prices unto the customer details.
def Choice_of_pizza():
for i in range(1,pizza_no +1): #Repeats a number of times (number user has inputted)
while True:
try: #Validating inputs
pizza_kind = int(input("Choice of pizza(s):"))
if pizza_kind < 1:
print("Refer to PIZZA MENU for number order")
continue
if pizza_kind > 12:
print("Refer to PIZZA MENU for number order")
continue
else:
pizza = pizza_kind - 1 #Makes the list start at 1
print('\nYou have chosen {}\n'.format(MENU[pizza_kind-1][0]))
customerOrder.append(MENU[pizza_kind-1])
for i in range(len(customerOrder)):
cost=+customerOrder[i][1]
global total_cost
total_cost=0
#Sum of the pizzas
global Combined_Total
if delivery == "D": #Adds $3 dollars to the total cost if delivery
total_cost=+cost
Combined_Total = total_cost + Delivery_cost
else: #Price stays the same if pick up
total_cost=+cost
Combined_Total = total_cost
break
except ValueError:#Validating inputs - accepts only numbers and can't be left blank
print("Please use numbers only")
continue
Choice_of_pizza(
The intended goal was, as the user input there choice one by one it takes out the name and places the price into the cost list but it doesn't seem to do that.
here's the original full code
#----------------------------important stuff-----------------------------------
#time delay
import time
#loop system for the details section
running = True #Loop
import re
Delivery_cost = 3.0
cost=[]
customerOrder=[]
customer_name=[]
customer_name_2=[]
customer_telephone_2=[]
house_no=[]
street_name=[]
#------------------------------menu list --------------------------------------
MENU =[
['1. Pepperoni pizza', 8.50], ['2. Hawaiian pizza', 8.50], ['3. Garlic cheese pizza (with choice of sauce)', 8.50],['4. Cheese pizza (with choice of sauce)', 8.50], ['5. Ham and cheese pizza', 8.50], ['6. Beef & onion pizza', 8.50], ['7. Vegetarian pizza', 8.50], ['8. BBQ chicken & bacon aioli pizza', 13.50], ['9. Boneless pizza (italian style anchovy with no bones)', 13.50], ['10. Pizza margherita', 13.50],['11. Meat-lover’s pizza', 13.50],['12. Tandoori pizza', 13.50]
]
#-----------------------------details------------------------------------
def pick_or_deli():
global delivery
delivery = input("P - pick up / D - delivery:")
delivery = delivery.upper() #Changes the letter inputted to an uppercase
if delivery == "D": #statement if person choosed delivery
while running == True:
global customer_name #This can be called when printing out final order and details
customer_name = input("Name:")
if not re.match("^[a-zA-Z ]*$", customer_name): #Checks whether input is letters only
print("Please use letters only")
elif len(customer_name) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
customer_name = customer_name.title()
break #Breaks the loop when valid input has been entered
while running == True:
global customer_telephone
customer_telephone = input("Telephone:")
if not re.match("^[0-9 ]*$", customer_telephone): #Checks whether input is numbers only
print("Please use numbers only")
elif len(customer_telephone) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
break #Breaks the loop when valid input has been entered
while running == True:
global house_no
house_no = input("House number:")
if not re.match("^[0-9 /]*$", house_no): #Checks whether input is numbers only
print("Please use numbers only")
elif len(house_no) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
break #Breaks the loop when valid input has been entered
while running == True:
global street_name
street_name = input("Street name:")
if not re.match("^[a-zA-Z ]*$", street_name): #Checks whether input is letters only
print("Please use letters only")
elif len(street_name) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
street_name = street_name.title()
break #Breaks the loop when valid input has been entered
elif delivery == "P": #statement for if person choosed pickup
while running == True:
global customer_name_2
customer_name_2 = input("Name:")
if not re.match("^[a-zA-Z ]*$", customer_name_2): #Checks whether input is letters only
print("Please use letters only")
elif len(customer_name_2) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
customer_name_2 = customer_name_2.title()
break #Breaks the loop when valid input has been entered
while running == True:
global customer_telephone_2
customer_telephone_2 = input("Telephone:")
if not re.match("^[0-9 ]*$", customer_telephone_2): #Checks whether input is numbers only
print("Please use numbers only")
elif len(customer_telephone_2) == 0: #User has not inputted anything, therefore invalid input
print("Please enter a valid input")
else:
break #Breaks the loop when valid input has been entered
else:
print("Please enter P or D")
pick_or_deli()
pick_or_deli()
#-----------------------------order script-------------------------------------
print('''\nWelcome to ~~~~~ Dream Pizza ~~~~~
To pick an order from the Menu pick the designated number that is next to the product.\n
From 1 for Pepperoni pizza.\n
Or 2 for Hawaiian pizza.\n
and so on.\n
The delivery cost is $3\n
To cancel the order throughout press 0 and it will reset itself.\n
But first decide how many pizza you want.\n''')
time.sleep(3.0)
#--------------menu text and design can be called again------------------------
def menu_design():
print(*MENU, sep = "\n")\
menu_design()
#------------------deciding how many pizzas they want---------------------------
def order():
global pizza_no
while True:
try: #Validating the inputs
pizza_no = int(input('''\nNo. of pizzas you want (min 1 - max 5):\n'''))
if pizza_no < 1:
print("Please order between 1 - 5 pizzas") #Checks whether input is between 1 and 5
continue
if pizza_no > 12:
print("Please order between 1 - 5 pizzas")
continue
else:
break #Breaks the loop when valid input has been entered
except ValueError: #Validating inputs - accepts only numbers and can't be left blank
print("Please use numbers only")
continue
order()
#--------------------------------picking pizza-----------------------------------
def Choice_of_pizza():
for i in range(1,pizza_no +1): #Repeats a number of times (number user has inputted)
while True:
try: #Validating inputs
pizza_kind = int(input("Choice of pizza(s):"))
if pizza_kind < 1:
print("Refer to PIZZA MENU for number order")
continue
if pizza_kind > 12:
print("Refer to PIZZA MENU for number order")
continue
else:
pizza = pizza_kind - 1 #Makes the list start at 1
print('\nYou have chosen {}\n'.format(MENU[pizza_kind-1][0]))
customerOrder.append(MENU[pizza_kind-1])
for i in range(len(customerOrder)):
cost=+customerOrder[i][1]
global total_cost
total_cost=0
#Sum of the pizzas
global Combined_Total
if delivery == "D": #Adds $3 dollars to the total cost if delivery
total_cost=+cost
Combined_Total = total_cost + Delivery_cost
else: #Price stays the same if pick up
total_cost=+cost
Combined_Total = total_cost
break
except ValueError:#Validating inputs - accepts only numbers and can't be left blank
print("Please use numbers only")
continue
Choice_of_pizza()
#-----------------------------------reciept---------------------------------------
def customerDetails(): #Prints customer order and details
if delivery == "D": #if person choosed delivery
print ("")
print ("CUSTOMER and ORDER DETAILS")
print ("")
print ('Name: {}' .format(customer_name))
print ('Telephone: {}' .format(customer_telephone))
print ('Address:')
print (house_no, street_name)
print ("")
print ('ORDER:')
print(*customerOrder, sep = "\n")
print ('Total Price: $ {:.2f}' .format(total_cost))
print ('Total Price + Delivery Cost: $ {:.2f}' .format(Combined_Total))
else: #if person choosed pickup don't have to speccify
print ("")
print ("CUSTOMER and ORDER DETAILS")
print ("")
print ('Name:{}' .format(customer_name_2))
print ('Telephone:{}' .format(customer_telephone_2))
print ("")
print ('ORDER:')
print(*customerOrder, sep = "\n")
print ('Total Price: {:.2f}' .format( total_cost))
customerDetails()
#-----------confrimation of customers order proceed or cancel---------------------
print ("")
def confirm(): #Confirms details of customer and order
confirmation = input("Y - confirm order / N - cancel order:")
confirmation = confirmation.upper() #Changes the letter inputted to an uppercase
if confirmation == "Y": #if Y is entered, order is confirmed
print("DETAILS CONFIRMED")
elif confirmation == "N": #if N is entered, order is cancelled
print("DETAILS CANCELLED - order has been reset")
customerOrder[:] = []
cost[:] = []
menu_design()
order()
Choice_of_pizza()
customerDetails()
confirm()
else:
print("Please enter Y or N") #If anything other than Y or N is entered, it will ask again
confirm()
confirm()
#----statement im customer would like to order more or finalised there order---
print ("")
def order_more(): #Placing another order
order_more = input("Z - order more / x - exit program:")
order_more = order_more.upper() #Changes the letter inputted to an uppercase
'''cost[:] = []'''
if order_more == "Z":
menu_design() #Calls the functions - will run the code that the def defines
order()
Choice_of_pizza()
customerDetails()
confirm()
print ("")
print ("THANK YOU FOR YOUR SHOPPING AT DREAMS PIZZA")
if delivery == "D":
print ("Your order will be delivered in 25mins") #Ending statement
elif delivery == "P":
print ("Your order will be ready to pick up in 20mins") #Ending statement
elif order_more == "X":
print ("")
print ("THANK YOU FOR YOUR ORDER")
if delivery == "D":
print ("Your order will be delivered in 25mins") #Ending statement
elif delivery == "P":
print ("Your order will be ready to pick up in 20mins") #Ending statement
else:
print ("Please enter X or Z") #If anything other than X or Z is entered, it will ask again
order_more()
order_more()
Also why I only have one list? it is because I was required to only use one
Code Issues:
For addition assignment the syntax is:
x += y # this assigns x to (x + y)
Not:
x = +y # this assign x to y
Glbols are not causing a problem in your code, but are usually frowned upon and negatively reflect on programming skills i.e. Why are Global Variables Evil?.
Choice_of_pizza function fix
def Choice_of_pizza():
for i in range(1,pizza_no +1): #Repeats a number of times (number user has inputted)
while True:
try: #Validating inputs
pizza_kind = int(input("Choice of pizza(s):"))
if pizza_kind < 1:
print("Refer to PIZZA MENU for number order")
continue
if pizza_kind > 12:
print("Refer to PIZZA MENU for number order")
continue
else:
pizza = pizza_kind - 1 #Makes the list start at 1
print('\nYou have chosen {}\n'.format(MENU[pizza_kind-1][0]))
customerOrder.append(MENU[pizza_kind-1])
cost = 0
for i in range(len(customerOrder)):
cost += customerOrder[i][1]
global total_cost # globals are discouraged
total_cost=0
#Sum of the pizzas
global Combined_Total # globals are discouraged
if delivery == "D": #Adds $3 dollars to the total cost if delivery
total_cost += cost
Combined_Total = total_cost + Delivery_cost
else: #Price stays the same if pick up
total_cost += cost
Combined_Total = total_cost
break
except ValueError:#Validating inputs - accepts only numbers and can't be left blank
print("Please use numbers only")
continue

Why does Python tell me this is not defined?

So I am trying to write a code that uses functions to create a menu for user input. It's basically just inputting the amount of dollars you wish and picking which currency to convert it to. I am absolutely lost because every time I attempt to run this code I have so far (Just to make sure I'm on the correct path), I input "1" and say 20 dollars just for example, it tells me that "dollars" is not defined when I clearly have it as a user input.
def DisplayMenu():
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = int(input("Enter your selection: "))
dollars = eval(input("Enter the dollar amount to convert: "))
def DollarConvert(selection, dollars):
if selection == "1":
conversion = dollars * 0.921
elif selection == "2":
conversion = dollars * 0.807
elif selection == "3":
conversion = dollars * 24.246
elif selection == "4":
conversion = dollars * 7.085
elif selection == "5":
conversion = dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
DisplayMenu()
print("$ ",dollars," = ",chr(8364),conversion)
Hopefully someone can help me with this because I am out of ideas
You never run or from DollarConvert(), or receive outputs from either function. Change the functions to return values, like this:
def DisplayMenu():
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = int(input("Enter your selection: "))
dollars = eval(input("Enter the dollar amount to convert: "))
return selection, dollars
def DollarConvert(selection, dollars):
if selection == "1":
return = dollars * 0.921
elif selection == "2":
return = dollars * 0.807
elif selection == "3":
return dollars * 24.246
elif selection == "4":
return dollars * 7.085
elif selection == "5":
return dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
return None
selection, dollars = DisplayMenu()
conversion = DollarConvert(selection, dollars)
print("$ ",dollars," = ",chr(8364),conversion)
There we go.
In your code, the dollars variable's scope is limited to inside that function. You have to return dollars from the function to make it accessible. Also your dollar convert function is never called, so you need to call it. You also need to add a return statement for the conversion variable. Returning is essential for most all functions, otherwise data is lost.
You could also do it using the global keyword
dollars = None
conversion = None
def DisplayMenu():
global dollars
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = input("Enter your selection: ")
dollars = int(input("Enter the dollar amount to convert: "))
DollarConvert(selection, dollars)
def DollarConvert(selection, dollars):
global conversion
if selection == "1":
conversion = dollars * 0.921
elif selection == "2":
conversion = dollars * 0.807
elif selection == "3":
conversion = dollars * 24.246
elif selection == "4":
conversion = dollars * 7.085
elif selection == "5":
conversion = dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
DisplayMenu()
print("$ ",dollars," = ",chr(8364),conversion)
Also, one more mistake on line 12 & 13, i.e
selection = int(input("Enter your selection: "))
changed to
selection = input("Enter your selection: ")
and
dollars = eval(input("Enter the dollar amount to convert: "))
changed to
dollars = int(input("Enter the dollar amount to convert: "))

Need help creating restaurant menu. Base cost, toppings, tax, total are the outputs

Pretty much the title. Wrote some code but I don't know whats wrong with it as it won't run. I don't know if its even close to right. This program is a mac and cheese program, the user chooses between small, medium, and large and can add toppings. It has to spit out the toppings cost, base cost, and total cost with tax. I think I'm close, but I'm pretty fresh to this whole programming thing, so help a guy out. :)
#Lab 8 Mac and Cheese Program
#This program calculates the cost of ordered mac and cheese
#Date: 10/10/19
#Welcome Message
print ("Thank you for your purchase! This program will calculate the total cost of your order.")
print('-'*65)
print()
#Declare Variables
small = 4.00
medium = 5.00
large = 6.00
bacon = 1.50
grilled_onions = 1.00
grilled_chicken = 2.50
sloppy_joe = 2.50
lobster = 5.00
def mainMenu():
print("1. Small $4.00")
print("2. Medium $5.00")
print("3. Large $6.00")
selection = int(input("What size Mac and Cheese would you like? Choose a number. ")
if selection == "1":
small()
elif selection == "2":
medium()
elif selection == "3":
large()
else:
print("Enter a valid selection" )
mainMenu()
def small():
small = 4.00
print("You have ordered a small Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = small
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + small)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
small()
def medium():
medium = 5.00
print("You have ordered a medium Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = medium
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + medium)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
medium()
def large():
large = 6.00
print("You have ordered a large Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == 1:
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = large
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + large)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
large()
mainMenu()
You might find it helpful to start with a trimmed down version of your program and get that to work. Just maybe "small." Also, the "def menu()" function appears to be repeated for each size. You might find it easier to work with/debug if you just have one "def menu()" that works more generally. Lastly, you might want to watch out for "ints vs. strings" in your processing. Hope that helps troubleshoot.

Categories