Complete in Python In this second part of the lab you will add on to your Class.
ID: 3827884 • Letter: C
Question
Complete in Python
In this second part of the lab you will add on to your Class. In addition to the number of patties a user can choose for their burger, they can also choose extra toppings. A typical burger comes with tomato, onion and pickles. Cheese, bacon, onion straws, grilled onions and grilled mushrooms are extra. These extra costs are as follows: Cheese = $0.75, Bacon = $1.00, Grilled and Grilled Mushrooms = $0.50.
Add to your class a method to determine the cost of the extras. This method will need to ask the user what type of topping they want. The user can choose multiple toppings (HINT: there needs to be a loop here). The method will then use this choice to determine an extras cost. That value needs to be added or summed with the other extras choices.
Also add to your class a method that will determine the total cost of the burger. This total will be based on the base cost as determined in the first part of the lab and the extras cost.
Finally include in your class methods that allow the extras cost and the total cost to leave the class.
Back in main() print out the extras cost and the total cost.
code from part one-
class BurgerCost:
#Constructor
def __init__(self, singleprice, doubleprice):
self.single_price = singleprice
self.double_price = doubleprice
#Calculation Methods
def cost(self, patty_type, number_of_patty):
if patty_type.upper() == "S":
return self.single_price * number_of_patty
elif patty_type.upper() == "D":
return self.double_price * number_of_patty
#Access Methods
def get_signle_price(self):
return self.single_price
def get_double_price(selfs):
return selfs.double_price
def main():
#declare variables
userburgertype = str()
#ask user for the type of burger
userburgertype = input("Enter S for a single patty burger or D for a double patty burger: ")
#creating the MyBurger object
MyBurger = BurgerCost(5.95 ,7.95)
print("Here is the cost of your burger:")
print(" Burger Cost: $", MyBurger.cost(userburgertype))
main()
Code from part 2-
class BurgerCost:
#Copy and paste code from part 1 here
def determineExtraCost(self):
#ask user for their extras
print("Enter your extras:")
print(" C = Cheese")
print(" B = Bacon")
print(" O = Grilled Onions")
print(" M = Grilled Mushrooms")
print(" Q = Quit")
self.__extratype = input()
#finish the rest
def main():
#declare variables
userburgertype = str()
#ask user for the type of burger
userburgertype = input("Enter S for a single patty burger or D for a double patty burger: ")
#display burger costs to the user
print("Here is the cost of your burger:")
print(" Burger Cost: $", #finish this
print(" Extra Costs: $", #finish this
print(" ---------")
print(" Total Cost: $", #finish this
print()
Output should look like this
1 class BurgerCost: 2 Copy and paste code from part 1 here 5 def determineExtracost self) ask user for their extras print ("Enter your extras: print ltC Cheese print ("VtB Bacon") print ("Vto Grilled onions" prin ("V Grilled Mushrooms tM 11 print ("Vt Quit") self extratype input 14 #finish the rest 15 17 18 def main() declare variables 20 userburgertype str() main.py Load default template...Explanation / Answer
CODE:
class BurgerCost():
#Constructor
def __init__(self, singleprice, doubleprice):
self.single_price = singleprice
self.double_price = doubleprice
#Calculation Methods
def cost(self, patty_type, number_of_patty):
_extraCost = self.determineExtraCost()
if patty_type.upper() == "S":
return (self.single_price * number_of_patty) + _extraCost
elif patty_type.upper() == "D":
return (self.double_price * number_of_patty) + _extraCost
def determineExtraCost(self):
#ask user for their extras
__extratypeCost = 0
while True:
print("Enter your extras:")
print(" C = Cheese")
print(" B = Bacon")
print(" O = Grilled Onions")
print(" M = Grilled Mushrooms")
print(" Q = Quit")
self.__extratype = raw_input()
if (self.__extratype == 'Q'):
break
elif (self.__extratype == 'M'):
__extratypeCost = __extratypeCost + 0.50
elif (self.__extratype == 'O'):
__extratypeCost = __extratypeCost + 0.50
elif (self.__extratype == 'B'):
__extratypeCost = __extratypeCost + 1
elif (self.__extratype == 'C'):
__extratypeCost = __extratypeCost + 0.75
return __extratypeCost
#Access Methods
def get_signle_price(self):
return self.single_price
def get_double_price(selfs):
return selfs.double_price
def main():
#declare variables
userburgertype = str()
#ask user for the type of burger
userburgertype = raw_input("Enter S for a single patty burger or D for a double patty burger: ")
#creating the MyBurger object
MyBurger = BurgerCost(5.95 ,7.95)
print("Here is the cost of your burger:")
if(userburgertype == 'S'):
print "Burger Cost: $" + str(MyBurger.cost(userburgertype,1))
elif (userburgertype == 'D'):
print "Burger Cost: $" + str(MyBurger.cost(userburgertype,2))
if __name__ == "__main__":
main()
OUTPUT:
$python burger.py
Enter S for a single patty burger or D for a double patty burger: S
Here is the cost of your burger:
Enter your extras:
C = Cheese
B = Bacon
O = Grilled Onions
M = Grilled Mushrooms
Q = Quit
C
Enter your extras:
C = Cheese
B = Bacon
O = Grilled Onions
M = Grilled Mushrooms
Q = Quit
Q
Burger Cost: $6.7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.