Cyclone Category Program

Cyclone Category Program

OBJECT ORIENTED PROGRAMMING

Question

Write a python application that displays a cyclone's category based on the user's input of the wind speed. The Cyclone Scale classifies cyclones into five categories numbered 1 through 5. The minimum sustained wind speeds for categories 4 through 1 are 260, 225, 170 and 125 km per hour, respectively. Category 5 cyclone has sustained winds of at least 280 km per hour. Any storm with winds of less than 125 km per hour is not a cyclone.

Solution

class Cyclone:
    def category1(self):
        print('This is a Category-1 cyclone which has sustained wind speed of 125 km per hour.')

    def category2(self):
        print('This is a Category-2 cyclone which has sustained wind speed of 170 km per hour.')

    def category3(self):
        print('This is a Category-3 cyclone which has sustained wind speed of 225 km per hour.')

    def category4(self):
        print('This is a Category-4 cyclone which has sustained wind speed of 260 km per hour.')

    def category5(self):
        print('This is a Category-5 cyclone which has sustained wind speed of at least 280 km per hour.')

    def calculate(self, speed):
        if 170 > speed >= 125:
            self.category1()
        elif 225 > speed >= 170:
            self.category2()
        elif 260 > speed >= 225:
            self.category3()
        elif 280 > speed >= 260:
            self.category4()
        elif speed >= 280:
            self.category5()
        else:
            print('It is not a Cyclone.')


while True:
    wind_speed = int(input('Enter the wind speed in km per hour: '))
    if wind_speed == 0:
        quit()
    Cyclone().calculate(wind_speed)
    print('Enter 0 to exit.')

Output

Cyclone Program Output

Explanation

The program categorizes the cyclones based on the wind speeds provided by the user. The user input wind_speed is passed as an argument to the calculate(self, speed) method of class Cyclone which compares the user input i.e, the speed with sustained wind speeds. Depending on the comparisons, respective category methods (like category1()) are called within the calculate method. The category methods contain suitable printing statements for each category of cyclones i.e, category 1 through 5.

Since the program is in an infinite loop, the user can continuously give the wind speed values. And the program is made to exit when the wind speed value entered is 0.


Top