0% found this document useful (0 votes)
2 views2 pages

Python Code Output

The document contains Python code defining several classes including 'car', 'toyotacar', 'cruiser', 'A', 'B', and 'C', showcasing inheritance and static methods. It also includes a 'student' class with a method to change the student's name and a property to calculate the percentage of marks. The code demonstrates object instantiation and method calls, along with the use of class variables and properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Code Output

The document contains Python code defining several classes including 'car', 'toyotacar', 'cruiser', 'A', 'B', and 'C', showcasing inheritance and static methods. It also includes a 'student' class with a method to change the student's name and a property to calculate the percentage of marks. The code demonstrates object instantiation and method calls, along with the use of class variables and properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

print("Try programiz.

pro")
class car:
color = "black"
@staticmethod
def start():
print("car started")
@staticmethod
def stop():
print("car stoped")

class toyotacar(car):
def __init__(self, origin):
self.origin = origin

class cruiser(toyotacar):
def __init__(self, type, milege, control):
# super().__init__(origin)
self.type = type
self.milege = milege
self.control = control

car1 = cruiser("diesel", "24kmpl", "semi-auto")


car2 = cruiser("petrol", "20kmpl", "manual")

# print(car1.origin)
print(car1.stop())

class A:
varA = "welcome to class A"

class B:
varB = "welcome to vlass B"

class C(A, B):


varC = "welcome to class C"

c1 = C()
c2 = C()

print(c1.varA)
print(c2.varA)

class student:
name = "rahul"

@classmethod
def changename(cls, name):
cls.name = name

s1 = student()
s2 = student()
s1.changename("anonymous")
print(s1.name)
print(student.name)
class student:
def __init__(self, phy, chem, maths):
self.phy = phy
self.chem = chem
self.maths = maths

@property
def cal_percentage(self):
return str(self.phy + self.chem + self.maths / 3) + " %"

s1 = student(76, 84, 86)


s1.phy = 86
print(s1.phy)
print(s1.cal_percentage)

You might also like