Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # September 2nd, 2019
- # Assignment 1, Good Morning America!
- # This program takes the input of what users want for breakfast
- # and then it calculates the price based on the individual components within the breakfast
- #
- # Boolean variable to check when q is pressed
- qPressed = False
- # A string array used to contain all the items in the menu
- menuItems = ["small breakfast", "regular breakfast", "big breakfast", "egg", "bacon"
- ,"sausage", "hash brown", "toast", "coffee", "tea"]
- # Constants used to represent the price of each menu item
- EGG_PRICE = 0.99
- BACON_PRICE = 0.49
- SAUSAGE_PRICE = 1.49
- HASHBROWN_PRICE = 1.19
- TOAST_PRICE = 0.79
- COFFEE_PRICE = 1.09
- TEA_PRICE = 0.89
- # variable used to track the price of the orders
- orderPrice = 0
- # variable used to store the amount of orders to be taken
- quantityOrder = 0
- # Function that formats the input
- def formatInput(textLine) :
- textLine = textLine.lower().strip()
- wordList = textLine.split()
- textLine = " ".join(wordList)
- return textLine
- # While loop to keep the menu operating until the user exits
- while not qPressed:
- # Prompts user what they want for breakfast
- print('Enter item (q to terminate): small breakfast, regular breakfast, big breakfast, '
- 'egg, bacon, sausage, hash brown, toast, coffee, tea:')
- # Takes the user's input for the menu option
- menuOrder = formatInput(input())
- # For loop to run through the array of the menu items
- for i in range(10):
- # If the input is equal to any of the menu items...
- if menuOrder == menuItems[i]:
- # Prompts the customer on how many of the desired item they want
- print("Enter quantity: ")
- # temporary variable used to store the input
- temp = input()
- # while loop to keep prompting the user to input a valid number until the user inputs a number
- while not temp.isnumeric():
- print("Please input a valid number")
- temp = input()
- # store the input into a variable that stores the amount of the menu item the customer ordered
- quantityOrder = int(temp)
- # If the item ordered is a small breakfast, charge them for one egg
- # one hashbrown, two slices of toast, two bacons, and one sausage
- # If more than one is ordered, it will be multiplied by the ordered amount
- if menuItems[i] == "small breakfast":
- orderPrice = orderPrice + quantityOrder*(EGG_PRICE + HASHBROWN_PRICE + 2*TOAST_PRICE +
- 2*BACON_PRICE + SAUSAGE_PRICE)
- # breaks from the for loop once ordered
- break
- # else if the item ordered is a regular breakfast, charge them for two eggs
- # one hashbrown,two slices of toast, four strips of bacon, and two sausages
- # If more than one is ordered, it will be multiplied by the ordered amount
- elif menuItems[i] == "regular breakfast":
- orderPrice = orderPrice + quantityOrder*(2*EGG_PRICE + HASHBROWN_PRICE + 2*TOAST_PRICE + 4*BACON_PRICE
- + 2*SAUSAGE_PRICE)
- # breaks from the for loop once ordered
- break
- # else if the item ordered is a big breakfast, charge them for the three eggs,
- # two hashbrowns, four slices of toast, six strips of bacon, and three sausages
- # If more than one is ordered, it will be multiplied by the ordered amount
- elif menuItems[i] == "big breakfast":
- orderPrice = orderPrice + quantityOrder*(3*EGG_PRICE + 2*HASHBROWN_PRICE + 4*TOAST_PRICE +
- 6*BACON_PRICE + 3*SAUSAGE_PRICE)
- # breaks from the for loop once ordered
- break
- # else if the item ordered is eggs charge them for the amount of eggs they ordered
- elif menuItems[i] == "egg":
- orderPrice = orderPrice + quantityOrder*EGG_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is bacon charge them for the amount of bacon they ordered
- elif menuItems[i] == "bacon":
- orderPrice = orderPrice + quantityOrder*BACON_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is sausage charge them for the amount of sausage they ordered
- elif menuItems[i] == "sausage":
- orderPrice = orderPrice + quantityOrder*SAUSAGE_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is hash brown charge them for the amount of hash browns they ordered
- elif menuItems[i] == "hash brown":
- orderPrice = orderPrice + quantityOrder*HASHBROWN_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is toast charge them for the amount of toast they ordered
- elif menuItems[i] == "toast":
- orderPrice = orderPrice + quantityOrder*TOAST_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is coffee charge them for the amount of coffee they ordered
- elif menuItems[i] == "coffee":
- orderPrice = orderPrice + quantityOrder*COFFEE_PRICE
- # breaks from the for loop once ordered
- break
- # else if the item ordered is tea charge them for the amount of tea they ordered
- elif menuItems[i] == "tea":
- orderPrice = orderPrice + quantityOrder*TEA_PRICE
- # breaks from the for loop once ordered
- break
- # else if the user presses q, make the boolean true
- elif menuOrder == "q":
- qPressed = True
- # else if the array is at its end and no values are equal to the menu items
- # prompt an error message
- elif i == len(menuItems)-1:
- print ("Error, please input a valid menu item")
- # Prints the cost of the breakfast before tax rounded to 2 decimal places
- print("Cost: " + str(round(orderPrice, 2)))
- # Prints the tax of the breakfast rounded to 2 decimal places
- print("Tax: " + str(round(0.13*orderPrice, 2)))
- # Prints the total price of the breakfast rounded to 2 decimal places
- print("Total: " + str(round(orderPrice + 0.13*orderPrice, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement