Muhammad Abbas
Muhammad Abbas
Muhammad Abbas
Class code
BSCS-2022
Semester
6th SEMESTER “A”
Roll no
CU-2816-2022
Lab Report #
“6th”
Department
Computer Science
Submitted to
Sir Sikandar Azam
Date
28th/April /2025
1. Class in Python
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
def make_sound(self):
print(f"{self.name} makes a sound.")
dog = Animal("Buddy", "Dog")
print(dog.name)
dog.make_sound()
OUTPUT:
2. Constructor in Python
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
car1 = Car("Toyota", "Camry")
print(car1.brand)
OUTPUT:
3. Implementation of Rational
Agent(LightSensorProject)
class LightSensorAgent:
def __init__(self):
self.light_detected = False
def perceive_environment(self, light_value):
if light_value > 0:
self.light_detected = True
else:
self.light_detected = False
def act(self):
if self.light_detected:
print("Light detected! Moving forward.")
else:
print("No light detected. Stopping.")
agent = LightSensorAgent()
agent.perceive_environment(light_value=5)
agent.act()
agent.perceive_environment(light_value=0)
agent.act()
OUTPUT: