1. Engineering
  2. Computer Science
  3. python 3 adjust the following code so the two errors...

Question: python 3 adjust the following code so the two errors...

Question details

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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution