Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON! 1. Write a Pizza class to that this client code works. Please note that

ID: 3662462 • Letter: P

Question

PYTHON!

1. Write a Pizza class to that this client code works. Please note that it is ok if the toppings are listed in a different order.

>>> pie = Pizza()

>>> pie Pizza('M',set())

>>> pie.setSize('L')

>>> pie.getSize() 'L'

>>> pie.addTopping('pepperoni')

>>> pie.addTopping('anchovies')

>>> pie.addTopping('mushrooms')

>>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})

>>> pie.addTopping('pepperoni')

>>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})

>>> pie.removeTopping('anchovies')

>>> pie Pizza('L',{'mushrooms', 'pepperoni'})

>>> pie.price() 16.65

>>> pie2 = Pizza('L',{'mushrooms','pepperoni'})

>>> pie2 Pizza('L',{'mushrooms', 'pepperoni'})

>>> pie==pie2 True

The Pizza class should have two attributes(data items):

size – a single character str, one of ‘S’,’M’,L”

toppings – a set containing the toppings.

If you don’t remember how to use a set, make sure you look it up in the book. Please note that toppings may be listed in a different order, but hw2TEST.py takes that into account.

The Pizza class should have the following methods/operators):

__init__ - constructs a Pizza of a given size (defaults to ‘M’)

and with a given set of toppings (defaults to empty set).

I highly recommend you look at the Queue class in the book to see how to get this to work correctly.

setSize – set pizza size to one of ‘S’,’M’or ‘L’

getSize – returns size add

Topping– adds a topping to the pizza, no duplicates, i.e., adding ‘pepperoni’ twice only adds it once

removeTopping – removes a topping from the pizza

price – returns the price of the pizza according to the following scheme:

‘S’: $6.25 plus 70 cents per topping

‘M’: $9.95 plus $1.45 per topping

‘L’: $12.95 plus $1.85 per topping

__repr__ - returns representation as a string – see output sample above. Note that toppings may be listed in a different order. __eq__ - two pizzas are equal if they have the same size and same toppings (toppings don’t need to be in the same order)

2. Write a function orderPizza that allows the user input to build a pizza. It then prints a thank you message, the cost of the pizza and then returns the Pizza that was built.

>>> orderPizza()

Welcome to Python Pizza!

What size pizza would you like (S,M,L): M

Type topping to add (or Enter to quit): mushroom

Type topping to add (or Enter to quit): onion

Type topping to add (or Enter to quit): garlic

Type topping to add (or Enter to quit):

Thanks for ordering!

Your pizza costs $14.299999999999999

Pizza('M',{'mushroom', 'onion', 'garlic'}) >>> orderPizza()

Welcome to Python Pizza! What size pizza would you like (S,M,L): L

Type topping to add (or Enter to quit): calamari

Type topping to add (or Enter to quit): garlic

Type topping to add (or Enter to quit):

Thanks for ordering!

Your pizza costs $16.65

Pizza('L',{'garlic', 'calamari'})

>>> p=orderPizza()

Welcome to Python Pizza!

What size pizza would you like (S,M,L): S

Type topping to add (or Enter to quit):

Thanks for ordering!

Your pizza costs $6.25

>>> p Pizza('S',set())

>>>

Explanation / Answer

I have written this below python class for pizza for various methods called..

setSize method will set the size of the pizza

getSize method will get the size of the pizza

setTopping mwthod will set the toppings to pizza

getTopping method wil get the toppings to pizza

orderPiza method will build the pizza

See the below pizza class

class Pizza:
'Pizaa Class have two attributes'
size = 'M'
   toppings = ''
  
def __init__(self, size, toppings):
self.size = size
self.toppings = toppings
Employee.empCount += 1

def setSize(self, size):
self.size = size

def getSize(self):
return size

def addtopppings(self, toppings):
self.toppings = toppings

def gettopppings(self):
return self.toppings
     
def orderPizza(self):
   print 'Welcome to Python Pizza'
   print 'What size Pizza would you like (S,M,L)'
   while (quit !='q')
       print 'Type topping to add (or Enter to quit press 'q')':
     
   print 'Thanks for ordering!'
     
   print 'Your Piza Costs is:'