#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

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter11: Introduction To Classes
Section11.4: A Case Study: Constructing A Date Class
Problem 7E
icon
Related questions
Question

#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):

        self.toppings.remove(topping)

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

    def price(self):

        # ‘S’: $6.25 plus 70 cents per topping

        if self.size == 'S':

            return 6.25+0.7*len(self.toppings)

        # ‘M’: $9.95 plus $1.45 per topping

        elif self.size == 'M':

            return 9.95+1.45*len(self.toppings)

        # ‘L’: $12.95 plus $1.85 per topping

        elif self.size == 'L':

            return 12.95+1.85*len(self.toppings)

    # __repr__ - returns representation as a string –

    def __repr__(self):

        # Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})

        return f"Pizza('{self.size}',{self.toppings})"

    # __eq__ - two pizzas are equal if they have the same size and same toppings

    # (toppings don’t need to be in the same order)

    def __eq__(self, value):

        if self.size != value.size:

            return False

        if self.toppings != value.toppings:

            return False

        return True

 

# testing

pie = Pizza()

print(pie)

# Pizza('M', set())

pie.setSize('L')

print(pie.getSize())

# 'L'

pie.addTopping('pepperoni')

pie.addTopping('anchovies')

pie.addTopping('mushrooms')

print(pie)

# Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})

pie.addTopping('pepperoni')

print(pie)

# Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})

pie.removeTopping('anchovies')

print(pie)

# Pizza('L',{'mushrooms', 'pepperoni'})

pie.price()

# 16.65

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

print(pie2)

# Pizza('L',{'mushrooms', 'pepperoni'})

print(pie == pie2)

# True

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'})
>>> prorderPizza()
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())
>>>
Transcribed Image Text: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'}) >>> prorderPizza() 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()) >>>
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr