Single Inheritance, multiple inheritance and multilevel inheritance in python.

Multilevel inheritance in python 

A program as an example.

Code -

--------------------------------

class ElectronicDevice:

    refrigerator = 1000


    def __init__(self, name, watt):

        self.name = name

        self.watt = watt


    def rupee_checker(self):

        a = 283

        if self.watt < 1000:

            return f"Your Electrical Device consumes less than {a} units per year."

        elif self.watt > 1000:

            return f"Your Electrical Device consumes more than {a} units per year."

        elif self.watt == 1000:

            return f"Your Electrical Device consumes {a} units per year."



class PocketGadget(ElectronicDevice):

    MaH = 3000


    def __init__(self, name, mah):

        self.name = name

        self.mah = mah


    def battery_life_checker(self):

        if self.mah < 20:

            return "Your gadget's battery will end in 3-4 days after full charging"

        elif self.mah > 20 and self.mah < 30:

            return "Your gadget's battery will end in 4-6 days after full charging"

        elif self.mah > 30 or self.mah == 30:

            return "Your gadget's battery will give backup up to 20 days after full charging"



class Phone(PocketGadget):

    battery = 4000


    def charging_speed_checker(self):

        if self.watt < 10:

            return "Your charger is a average charger"

        elif self.watt > 10 and self.watt < 20:

            return "Your charger is a average charger"

        elif self.watt < 33:

            return "Your charger is not a fast charger."

        elif self.watt > 33:

            return "Your charger is absolutely a fast charger."

        elif self.watt == 33:

            return "Your charger is a fast charger."



refrigerator = ElectronicDevice("refrigerator", 1000)

watch = PocketGadget("Pocket Watch", 40)

samsung_galaxy_j4 = Phone("Samsung Galaxy J4+", 23)

# print(samsung_galaxy_j4.charging_speed_checker())

print(watch.battery_life_checker())

Comments

Popular posts from this blog

Shopping Bill Generator In python.

Should we start preparation for BCA/MCA from class 11th ? How ?

Python program to check that a list have elements in it or not .