Question
Python 3+ Adjust the following code so the two errors below are non-present: 1. __init__() : Since Pizza object don't have it's own set() datastructure,
Python 3+
Adjust the following code so the two errors below are non-present:
1. __init__() : Since Pizza object don't have it's own set() datastructure, the toppings in the pizza object are manimupated from out of the object. (-1.0) 2. __eq__() : How about "self.toppings == other.toppings" rather than "self.toppings - other.toppin == set())".
Code:
## Program 1 ## ---------------------------------
class Pizza: def __init__(self, s='M', top=set()): self.setSize(s) self.toppings = top
def setSize(self, s): self.size = s
def getSize(self): return self.size
def addTopping(self, top): self.toppings.add(top)
def removeTopping(self, top): self.toppings.remove(top)
def price(self): if self.size == 'S': return 6.25 + (0.7 * len(self.toppings)) elif self.size == 'M': return 9.95 + (1.45 * len(self.toppings)) else: return 12.95 + (1.85 * len(self.toppings))
def __repr__(self): end = 'Pizza(' end += ('\'' + self.size + '\'') end += ',' end += str(self.toppings) end += ')' return end
def __eq__(self, other): return self.size == other.size and (self.toppings - other.toppings == set ())
## Program 2 ## ---------------------------------
def orderPizza(): print('Welcome to Python Pizza!') size = input('What size pizza would you like (S,M,L): ') za = Pizza(size, set()) while True: topping = input('Type topping to add (or Enter to quit): ') if topping == '': break else: za.addTopping(topping) print('Thanks for ordering!') print('Your pizza costs $' + str(za.price())) return za
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started