Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.53 KB | None | 0 0
  1. #
  2. # September 2nd, 2019
  3. # Assignment 1, Good Morning America!
  4. # This program takes the input of what users want for breakfast
  5. # and then it calculates the price based on the individual components within the breakfast
  6. #
  7.  
  8.  
  9.  
  10. # Boolean variable to check when q is pressed
  11. qPressed = False
  12. # A string array used to contain all the items in the menu
  13. menuItems = ["small breakfast", "regular breakfast", "big breakfast", "egg", "bacon"
  14.              ,"sausage", "hash brown", "toast", "coffee", "tea"]
  15.  
  16. # Constants used to represent the price of each menu item
  17. EGG_PRICE = 0.99
  18. BACON_PRICE = 0.49
  19. SAUSAGE_PRICE = 1.49
  20. HASHBROWN_PRICE = 1.19
  21. TOAST_PRICE = 0.79
  22. COFFEE_PRICE = 1.09
  23. TEA_PRICE = 0.89
  24.  
  25. # variable used to track the price of the orders
  26. orderPrice = 0
  27. # variable used to store the amount of orders to be taken
  28. quantityOrder = 0
  29.  
  30. # Function that formats the input
  31. def formatInput(textLine) :
  32.     textLine = textLine.lower().strip()
  33.     wordList = textLine.split()
  34.     textLine = " ".join(wordList)
  35.     return textLine
  36.  
  37.  
  38.  
  39. # While loop to keep the menu operating until the user exits
  40. while not qPressed:
  41.     # Prompts user what they want for breakfast
  42.     print('Enter item (q to terminate): small breakfast, regular breakfast, big breakfast, '
  43.           'egg, bacon, sausage, hash brown, toast, coffee, tea:')
  44.     # Takes the user's input for the menu option
  45.     menuOrder = formatInput(input())
  46.  
  47.     # For loop to run through the array of the menu items
  48.     for i in range(10):
  49.         # If the input is equal to any of the menu items...
  50.         if menuOrder == menuItems[i]:
  51.             # Prompts the customer on how many of the desired item they want
  52.             print("Enter quantity: ")
  53.  
  54.             # temporary variable used to store the input
  55.             temp = input()
  56.  
  57.             # while loop to keep prompting the user to input a valid number until the user inputs a number
  58.             while not temp.isnumeric():
  59.                 print("Please input a valid number")
  60.                 temp = input()
  61.  
  62.             # store the input into a variable that stores the amount of the menu item the customer ordered
  63.             quantityOrder = int(temp)
  64.  
  65.  
  66.             # If the item ordered is a small breakfast, charge them for one egg
  67.             # one hashbrown, two slices of toast, two bacons, and one sausage
  68.             # If more than one is ordered, it will be multiplied by the ordered amount
  69.             if menuItems[i] == "small breakfast":
  70.                 orderPrice = orderPrice + quantityOrder*(EGG_PRICE + HASHBROWN_PRICE + 2*TOAST_PRICE +
  71.                              2*BACON_PRICE + SAUSAGE_PRICE)
  72.                 # breaks from the for loop once ordered
  73.                 break
  74.             # else if the item ordered is a regular breakfast, charge them for two eggs
  75.             # one hashbrown,two slices of toast, four strips of bacon, and two sausages
  76.             # If more than one is ordered, it will be multiplied by the ordered amount
  77.             elif menuItems[i] == "regular breakfast":
  78.                 orderPrice = orderPrice + quantityOrder*(2*EGG_PRICE + HASHBROWN_PRICE + 2*TOAST_PRICE + 4*BACON_PRICE
  79.                              + 2*SAUSAGE_PRICE)
  80.                 # breaks from the for loop once ordered
  81.                 break
  82.             # else if the item ordered is a big breakfast, charge them for the three eggs,
  83.             # two hashbrowns, four slices of toast, six strips of bacon, and three sausages
  84.             # If more than one is ordered, it will be multiplied by the ordered amount
  85.             elif menuItems[i] == "big breakfast":
  86.                 orderPrice = orderPrice + quantityOrder*(3*EGG_PRICE + 2*HASHBROWN_PRICE + 4*TOAST_PRICE +
  87.                              6*BACON_PRICE + 3*SAUSAGE_PRICE)
  88.                 # breaks from the for loop once ordered
  89.                 break
  90.             # else if the item ordered is eggs charge them for the amount of eggs they ordered
  91.             elif menuItems[i] == "egg":
  92.                 orderPrice = orderPrice + quantityOrder*EGG_PRICE
  93.                 # breaks from the for loop once ordered
  94.                 break
  95.             # else if the item ordered is bacon charge them for the amount of bacon they ordered
  96.             elif menuItems[i] == "bacon":
  97.                 orderPrice = orderPrice + quantityOrder*BACON_PRICE
  98.                 # breaks from the for loop once ordered
  99.                 break
  100.             # else if the item ordered is sausage charge them for the amount of sausage they ordered
  101.             elif menuItems[i] == "sausage":
  102.                 orderPrice = orderPrice + quantityOrder*SAUSAGE_PRICE
  103.                 # breaks from the for loop once ordered
  104.                 break
  105.             # else if the item ordered is hash brown charge them for the amount of hash browns they ordered
  106.             elif menuItems[i] == "hash brown":
  107.                 orderPrice = orderPrice + quantityOrder*HASHBROWN_PRICE
  108.                 # breaks from the for loop once ordered
  109.                 break
  110.             # else if the item ordered is toast charge them for the amount of toast they ordered
  111.             elif menuItems[i] == "toast":
  112.                 orderPrice = orderPrice + quantityOrder*TOAST_PRICE
  113.                 # breaks from the for loop once ordered
  114.                 break
  115.             # else if the item ordered is coffee charge them for the amount of coffee they ordered
  116.             elif menuItems[i] == "coffee":
  117.                 orderPrice = orderPrice + quantityOrder*COFFEE_PRICE
  118.                 # breaks from the for loop once ordered
  119.                 break
  120.             # else if the item ordered is tea charge them for the amount of tea they ordered
  121.             elif menuItems[i] == "tea":
  122.                 orderPrice = orderPrice + quantityOrder*TEA_PRICE
  123.                 # breaks from the for loop once ordered
  124.                 break
  125.  
  126.         # else if the user presses q, make the boolean true
  127.         elif menuOrder == "q":
  128.             qPressed = True
  129.         # else if the array is at its end and no values are equal to the menu items
  130.         # prompt an error message
  131.         elif i == len(menuItems)-1:
  132.             print ("Error, please input a valid menu item")
  133.  
  134.  
  135.  
  136.  
  137.  
  138. # Prints the cost of the breakfast before tax rounded to 2 decimal places
  139. print("Cost: " + str(round(orderPrice, 2)))
  140. # Prints the tax of the breakfast rounded to 2 decimal places
  141. print("Tax: " + str(round(0.13*orderPrice, 2)))
  142. # Prints the total price of the breakfast rounded to 2 decimal places
  143. print("Total: " + str(round(orderPrice + 0.13*orderPrice, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement