Please use Python for this question. Make sure the code is formatted properly as well.
Write a Pizza class so that this client code works. Please note that it is ok if the toppings are listed in a different order.
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
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 don’t need to be in the same order)
Output for this question:
>>> pie = Pizza()
>>> pie
Pizza('M',set())
>>> pie.setSize('L')
>>> pie.getSize()
'L'
>>> pie.addTopping('pepperoni')
>>> pie
Pizza('L',{'pepperoni'})
>>> pie.addTopping('anchovies')
>>> pie.addTopping('mushrooms')
>>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})
True
>>> pie.addTopping('pepperoni')
>>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})
True
>>> pie.removeTopping('anchovies')
>>> pie==Pizza('L',{'mushrooms', 'pepperoni'})
True
>>> pie.price()
16.65
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('hw8TEST.py')
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- Written in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forwardIn C++ Define a class called textLines that will be used to store a list of lines of text (each line can be specified as a string). Use a dynamic array to store the list. In addition, you should have a private data member that specifies the length of the list. Create a constructor that takes a file name as parameter, and fills up the list with lines from the file. Make sure that you set the dynamic array to expand large enough to hold all the lines from the file. Also, create a constructor that takes an integer parameter that sets the size of an empty list. Write member functions to: remove and return the last line from the list add a new line onto the end of the list, if there is room for it, otherwise print a message and expand the array empty the entire list return the number of lines still on the list take two lists and return one combined list (with no duplicates) copy constructor to support deep copying remember the destructor!arrow_forwardCreate a Point classCreate a Point class as we did in the class. We'll use this to create Point objects that hold x,y coordinates of locations where we'll want to draw. Draw DotsWrite a drawDots(points) function that takes a list points as input and draws a dot on the drawing window for each Point. For example, you should be able to call your function as follows: >>> p = Point(10, 20) >>> q = Point(20, 30) >>> points = [p, q] >>> drawDots(points)arrow_forward
- Written in Python with docstring please if applicable Thank youarrow_forwardIn python and include doctring: First, write a class named Movie that has four data members: title, genre, director, and year. It should have: an init method that takes as arguments the title, genre, director, and year (in that order) and assigns them to the data members. The year is an integer and the others are strings. get methods for each of the data members (get_title, get_genre, get_director, and get_year). Next write a class named StreamingService that has two data members: name and catalog. the catalog is a dictionary of Movies, with the titles as the keys and the Movie objects as the corresponding values (you can assume there aren't any Movies with the same title). The StreamingService class should have: an init method that takes the name as an argument, and assigns it to the name data member. The catalog data member should be initialized to an empty dictionary. get methods for each of the data members (get_name and get_catalog). a method named add_movie that takes a Movie…arrow_forwardin c++ codearrow_forward
- #Python IDLE: #Below is my Pizza class ,how would I write the function described in the attached image,based on this class? # The Pizza class should have two attributes(data items): class Pizza: # 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). def __init__(self, size='M', toppings=set()): self.size = size self.toppings = toppings # setSize – set pizza size to one of ‘S’,’M’or ‘L’ def setSize(self, size): self.size = size # getSize – returns size def getSize(self): return self.size # addTopping – adds a topping to the pizza, no duplicates, i.e., adding ‘pepperoni’ twice only adds it once def addTopping(self, topping): self.toppings.add(topping) # removeTopping – removes a topping from the pizza def removeTopping(self, topping):…arrow_forwardIn GO language. Create a struct that has student name, id, and GPA. Write functions to create a student, modify the student’s id, and modify the student's GPA, and print the student’s information. (This is like creating a class and methods). Now create an array of three students and test your functions. You may hardcode your values if using a web conpiler. (Please hardcode the values!)arrow_forwardIn C++ Create a class called Student. Each student should have a name and ID number (an int). They should also have a ptr to a dynamic array called Grades. The public methods for Student should be: getName, setName, getID, setID, setGrades, getGrades. In the constructor you should initialize Grades to be an array of size 4 with the values 0 for each position. Make sure that you use THIS properly. Create 2 students, assign one object to another and show that when you assign grades to one it effects the other equally.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education