>>> roman_candle = RomanCandle ("example") >>> launches = roman_candle. launch_several (4) >>> roman_candle.noise_made 360 >>> roman_candle.noise_complaints Θ >>> print(roman_candle.calculate_complaints()) Received 1 new noise complaints. Explanation: - after 4 launches, the noise is 150 +30 + 150 + 30 = 360 - before .calculate_complaints() is called, the noise_complaints attribute is 0 - when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints is currently 0, so there is 1 - 0 = 1 new noise complaints noise_complaints // 4 = 1 // 4 = 0, so cops are not called >>> roman_candle.noise_complaints 1 >>> launches = roman_candle. launch_several (10) >>> roman_candle.noise_made 1260 >>> print(roman_candle.calculate_complaints()) COPS CALLED!! Received 4 new noise complaints. Explanation: - when .calculate_complaints() is called, noise_complaints is set to 1 - after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260 - 1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4 new noise complaints noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so cops are called

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

class Firework:
    """
    Implementation of the base Firework class
    """

    def __init__(self, brand):
        """ Constructor """
        self.brand = brand
        self.brightness = 5
        self.launches = 0
        self.noise_made = 0
        self.noise_complaints = 0

    def launch(self):
        """
        Launch a firework, updates noise_made and returns string
        """
        self.launches += 1
        if self.launches % 2 == 1:
            execute = 'successful'
            noise = 150
        else:
            execute = 'dud'
            noise = 30
        self.noise_made += noise
        return ("The " + self.brand + " firework was launched and it was a "
            + execute + " launch. It created "
            + str(noise) + " decibels of noise.")
        
    def launch_several(self, amount):
        """
        Launches fireworks `amount` of times, returns the full string
        """
        results = ""
        for _ in range(amount):
            results += self.launch() + "\n"
        return results.rstrip("\n")

class Firecracker(Firework):
    """
    Implementation of the Firecracker class
    """

    def __init__(self, brand):
        """ Constructor, set initial brightness """
        super().__init__(brand) 
        self.brightness = 3

    def calculate_complaints(self):
        """
        Calculates the number of noise complaints received
        """
        new_complaints = self.noise_made // 250 - self.noise_complaints
        if new_complaints > 0:
            self.noise_complaints += new_complaints
            return "Received " + str(new_complaints) + " new noise complaints."
        else:
            return "No new complaints!"

        
class RomanCandle(Firecracker):
    """
    Implementation of the RomanCandle class
    """

    def __init__(self, brand):
        """ Constructor, set initial brightness """
        self.cops_called = 0
        super().__init__(brand) 

    def calculate_complaints(self):
        """ Returns a message describing the number of complaints """
        if self.noise_complaints // 4 > self.cops_called : 
            self.cops_called += 1
            return 'COPS CALLED!!\n' + super().calculate_complaints()
        else:
            return super().calculate_complaints()

360
0
Received 1 new noise complaints.
1
1260
Received 4 new noise complaints.
0


** Process exited - Return Code: 0 **
Press Enter to exit terminal

only fix def calculate_complaints(self) in side of class RomanCandle(Firecracker)

>>> roman_candle = RomanCandle ("example")
>>> launches = roman_candle. launch_several (4)
>>> roman_candle.noise_made
360
>>> roman_candle.noise_complaints
Θ
>>> print(roman_candle.calculate_complaints())
Received 1 new noise complaints.
Explanation:
- after 4 launches, the noise is 150 +30 + 150 + 30 = 360
- before .calculate_complaints() is called, the noise_complaints attribute is 0
-
when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints
is currently 0, so there is 1 - 0 = 1 new noise complaints
noise_complaints // 4 = 1 // 4 = 0, so cops are not called
>>> roman_candle.noise_complaints
1
>>> launches = roman_candle. launch_several (10)
>>> roman_candle.noise_made
1260
>>> print(roman_candle.calculate_complaints())
COPS CALLED!!
Received 4 new noise complaints.
Explanation:
- when .calculate_complaints() is called, noise_complaints is set to 1
- after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260
-
1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4
new noise complaints
noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so
cops are called
Transcribed Image Text:>>> roman_candle = RomanCandle ("example") >>> launches = roman_candle. launch_several (4) >>> roman_candle.noise_made 360 >>> roman_candle.noise_complaints Θ >>> print(roman_candle.calculate_complaints()) Received 1 new noise complaints. Explanation: - after 4 launches, the noise is 150 +30 + 150 + 30 = 360 - before .calculate_complaints() is called, the noise_complaints attribute is 0 - when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints is currently 0, so there is 1 - 0 = 1 new noise complaints noise_complaints // 4 = 1 // 4 = 0, so cops are not called >>> roman_candle.noise_complaints 1 >>> launches = roman_candle. launch_several (10) >>> roman_candle.noise_made 1260 >>> print(roman_candle.calculate_complaints()) COPS CALLED!! Received 4 new noise complaints. Explanation: - when .calculate_complaints() is called, noise_complaints is set to 1 - after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260 - 1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4 new noise complaints noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so cops are called
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education