0% found this document useful (0 votes)
0 views8 pages

Python Lab Assignment - Apr 11-04

The document contains a Python lab assignment with various programming questions focused on object-oriented concepts. Each question includes class definitions and method implementations, demonstrating inheritance, method overriding, and object instantiation. The output for each question is provided, showcasing the results of the executed code.

Uploaded by

gundalauttham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

Python Lab Assignment - Apr 11-04

The document contains a Python lab assignment with various programming questions focused on object-oriented concepts. Each question includes class definitions and method implementations, demonstrating inheritance, method overriding, and object instantiation. The output for each question is provided, showcasing the results of the executed code.

Uploaded by

gundalauttham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PYTHON LAB

ASSIGNMENT [11/04/2025]
HT NO:2405A41216
BATCH :09 OUTPUT

#QUESTION : 1

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

person1 = Person("Alice", 30)


person2 = Person("Bob", 25)

print(f"Person 1: Name - {person1.name}, Age - {person1.age}")


print(f"Person 2: Name - {person2.name}, Age - {person2.age}")

OUTPUT
Person 1: Name - Alice, Age - 30

Person 2: Name - Bob, Age – 25

#QUESTION : 2

class Car:
def start(self):
print("Car starting with engine...")

class ElectricCar(Car):
def start(self):
print("Electric car starting with battery...")

car = Car()
electric_car = ElectricCar()

car.start()
electric_car.start()

OUTPUT
Car starting with engine...

Electric car starting with battery...

#QUESTION : 3

class Student:
def __init__(self, name, marks):
self.name = name
self.marks = marks

def check_pass_fail(self):
if self.marks >= 35:
return "Passed"
else:
return "Failed"

student1 = Student("SHIVA", 40)


student2 = Student("David", 30)

print(f"{student1.name}: {student1.check_pass_fail()}")
print(f"{student2.name}: {student2.check_pass_fail()}")

OUTPUT
SHIVA: Passed

David: Failed
#QUESTION : 4

class Animal:
def sound(self):
print("Generic animal sound")

class Dog(Animal):
def sound(self):
print("Bark")

class Cat(Animal):
def sound(self):
print("Meow")

dog = Dog()
cat = Cat()

dog.sound()
cat.sound()

OUTPUT
Bark
Meow

#QUESTION : 5

class Calculator:
def add(self, a, b):
return a + b

def subtract(self, a, b):


return a - b

def multiply(self, a, b):


return a * b

def divide(self, a, b):


if b != 0:
return a / b
else:
return "Division by zero error"
calculator = Calculator()

print(calculator.add(5, 3))
print(calculator.subtract(10, 4))
print(calculator.multiply(2, 6))
print(calculator.divide(12, 3))

OUTPUT
8
6
12
4.0

#QUESTION : 6

class Employee:
def __init__(self, name, id, salary):
self.name = name
self.id = id
self.salary = salary

class Manager(Employee):
def __init__(self, name, id, salary, department):
super().__init__(name, id, salary)
self.department = department

employee = Employee("shiva", 101, 50000)


manager = Manager("vashi", 102, 80000, "HR")

print(employee.name, employee.id, employee.salary)


print(manager.name, manager.id, manager.salary, manager.department)

OUTPUT
shiva 101 50000

vashi 102 80000 HR


#QUESTION : 7

class MyClass:
def greet(self, name="shiva"):
print("Hello,", name)

obj = MyClass()
obj.greet()
obj.greet("ravi")

OUTPUT
Hello, shiva

Hello, ravi

#QUESTION : 8

import math

class Shape:
def area(self):
pass

class Circle(Shape):
def __init__(self, radius):
self.radius = radius

def area(self):
return math.pi * self.radius**2

class Rectangle(Shape):
def __init__(self, length, width):
self.length = length
self.width = width

def area(self):
return self.length * self.width

circle = Circle(5)
rectangle = Rectangle(4, 6)

print(circle.area())
print(rectangle.area())

OUTPUT
78.53981633974483
24

#QUESTION : 9

class Book:
total_books = 0

def __init__(self, title, author):


self.title = title
self.author = author
Book.total_books += 1

book1 = Book("The Hitchhiker's Guide to the Galaxy", "Douglas Adams")


book2 = Book("To Kill a Mockingbird", "Harper Lee")
book3 = Book("Pride and Prejudice", "Jane Austen")

print(Book.total_books)

OUTPUT
3

#QUESTION : 10

class BankAccount:
def __init__(self, account_holder, balance=0):
self._account_holder = account_holder
self._balance = balance

def deposit(self, amount):


if amount > 0:
self._balance += amount
def withdraw(self, amount):
if 0 < amount <= self._balance:
self._balance -= amount

def get_balance(self):
return self._balance

account = BankAccount("shiva", 1000)


account.deposit(500)
account.withdraw(200)
print(account.get_balance())

OUTPUT
1300

#QUESTION : 11

class LivingBeing:
def breathe(self):
print("Breathing...")

class Animal(LivingBeing):
def move(self):
print("Moving...")

class Dog(Animal):
def bark(self):
print("Barking...")

dog = Dog()
dog.breathe()
dog.move()
dog.bark()

OUTPUT
Breathing...
Moving...
Barking...

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy