0% found this document useful (0 votes)
6 views3 pages

CMSC203-Ordoñez Juan Carlos-ClassesandObjects

The document contains Python programming exercises related to class definitions and object-oriented programming concepts. It includes examples of defining class attributes, checking object types, creating instance attributes, and defining a class without variables or methods. The exercises focus on a Vehicle class and its instances, demonstrating basic programming principles in Python.

Uploaded by

osbornejc20
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)
6 views3 pages

CMSC203-Ordoñez Juan Carlos-ClassesandObjects

The document contains Python programming exercises related to class definitions and object-oriented programming concepts. It includes examples of defining class attributes, checking object types, creating instance attributes, and defining a class without variables or methods. The exercises focus on a Vehicle class and its instances, demonstrating basic programming principles in Python.

Uploaded by

osbornejc20
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/ 3

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

You might also like