Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  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 dont 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,Mor L

getSize returns size

addTopping 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 dont need to be in the same order)

Please make sure all tests below pass in idle

Note: In the following code,

p==p2 shoudl be False. If True

than they are sharing the same set (or list) of toppings

You need to make sure that the set() constructor is

called in all cases in the body of the Pizza

constructor. See course notes for the Queue class.

>>> p = Pizza()

>>> p2 = Pizza()

>>> p.addTopping('mushroom')

>>> p2.addTopping('onion')

>>> p.addTopping('mushroom')

>>> p

Pizza('M',{'mushroom'})

>>> p2

Pizza('M',{'onion'})

>>> p==p2 # see note in TEST file

False

>>>

##### reroute stdin #####

code below directs input to be received from above

should not cause an error

>>> import sys

>>> si = sys.stdin

>>> sys.stdin = open('hw2TEST.py')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions