Republic of the Philippines
LAGUNA STATE POLYTECHNIC UNIVERSITY
Sta. Cruz Main Campus
Name: Ordoñez, Juan Carlos G. Date: 14-09-23
Yr. & Section: BSCS - 2B
1. Define a property that must have the same value for every class instance (object).
Define a class attribute”color” with a default value green. Every Vehicle should be
white.
class Vehicle:
color = "White"
def __init__(self, name, max_speed, mileage):
self.name = name
self.max_speed = max_speed
self.mileage = mileage
Ducati = Vehicle("Ducati", 210, 20)
Ferrari = Vehicle("Ferrari", 300, 25)
print(f"Color: {Ducati.color}, Vehicle name: {Ducati.name}, Speed: {Ducati.max_speed},
Mileage: {Ducati.mileage}")
print(f"Color: {Ferrari.color}, Vehicle name: {Ferrari.name}, Speed: {Ferrari.max_speed},
Mileage: {Ferrari.mileage}")
Republic of the Philippines
LAGUNA STATE POLYTECHNIC UNIVERSITY
Sta. Cruz Main Campus
2. Check type of an object. Write a program to determine which class a given Bus object
belongs to. Use Python’s built-in function.
class Vehicle:
def __init__(self, name, mileage, capacity):
self.name = name
self.mileage = mileage
self.capacity = capacity
def display_info(self):
print(f"Bus Name: {self.name}, Mileage: {self.mileage} Miles, Capacity: {self.capacity}
pax")
School_bus = Vehicle("LSPU Bus", 25, 100)
print("Information about School bus:")
School_bus.display_info()
3. Write a Python program to create a Vehicle class
with max_speed and mileage instance attributes.
class Vehicle:
def __init__(self, max_speed, mileage):
self.max_speed = max_speed
self.mileage = mileage
my_vehicle = Vehicle(300, 25)
print("Max Speed:", my_vehicle.max_speed, "Mileage:", my_vehicle.mileage)
Republic of the Philippines
LAGUNA STATE POLYTECHNIC UNIVERSITY
Sta. Cruz Main Campus
4. Create any animal class without any variables and methods?
class Elephant:
pass