0% found this document useful (0 votes)
23 views10 pages

Assignment No.6: Name: Korale Aboli Pramod Enroll No.2306099 Div: H2

The document contains Python code examples demonstrating the use of default modules such as math, os, and random, as well as user-defined packages and inheritance types including single, multiple, and multilevel inheritance. It includes code snippets for calculating square roots, creating directories, and implementing classes for employees, students, teachers, and animals. The document serves as an assignment submission for a programming course.

Uploaded by

shrutimanval104
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)
23 views10 pages

Assignment No.6: Name: Korale Aboli Pramod Enroll No.2306099 Div: H2

The document contains Python code examples demonstrating the use of default modules such as math, os, and random, as well as user-defined packages and inheritance types including single, multiple, and multilevel inheritance. It includes code snippets for calculating square roots, creating directories, and implementing classes for employees, students, teachers, and animals. The document serves as an assignment submission for a programming course.

Uploaded by

shrutimanval104
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/ 10

SLA

Name: Korale Aboli Pramod


Enroll No.2306099
Div : H2
Assignment No.6

Q: Write a python code which demonstrate the use of default modules.


Ans:
#***Math Module***

Import math
number = 25
sqrt_result = math.sqrt(number)
print("Square root of", number, "is", sqrt_result)

result = math.pow(15,6)
print("2 raised to the power of 3 is", result)

pi_value = math.pi
print("Value of Pi:", pi_value)

number = 19.7
rounded_value = math.ceil(number)
print("Rounded up value of", number, "is", rounded_value)
number = 9
factorial_result = math.factorial(number)
print("Factorial of", number, "is", factorial_result)
#***OS Module***

import os

current_directory = os.getcwd()
print("Current working directory:", current_directory)

print("\nList of files in the current directory:", os.listdir())

os.mkdir('folder')
print("New directory 'folder' created successfully.")

os.rmdir('folder')
print("Directory 'folder' removed successfully.")
#***Random Module ***
import random
random_number = random.randint(1, 10)
print(random_number)

sample_list = ['Anvi', 'Manthan', 'Shivraj']


random_item = random.choice(sample_list)
print(random_item)

numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)
print("Shuffled numbers:", numbers)
Assignment No.7

Q. Write a python program to create userdefined package for particular


problem.

Ans :
Structure of Package:

Arithmetic.py
Geometry.py :

Main.py :
OUTPUT:
Assignment No : 8

Q.Write a program to show use of inheritance


1) Single 2) Multiple 3) Multilevel

Ans :

# Single Inheritance
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary

def display_info(self):
print(f"\nEmployee Name: {self.name}, Salary: {self.salary}")

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

def display_manager_info(self):
print(f"\nManager Name: {self.name}, Salary: {self.salary}, Department:
{self.department}")

print("\nSingle Inheritance Example: Employee and Manager")


m = Manager("Shruti", 50000, "IT")
m.display_info()
m.display_manager_info()

OUTPUT :
#Multiple Inheritance

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

def display(self):
print(f"Name: {self.name}, Age: {self.age}")

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

def show_student_info(self):
print(f"Student ID: {self.student_id}, Course: {self.course}")

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

def show_teacher_info(self):
print(f"Teacher ID: {self.teacher_id}, Subject: {self.subject}")

class CollegeMember(Student, Teacher):


def __init__(self, name, age, student_id, course, teacher_id, subject):
Student.__init__(self, name, age, student_id, course)
Teacher.__init__(self, name, age, teacher_id, subject)

def show_details(self):
self.display()
self.show_student_info()
self.show_teacher_info()

college_member = CollegeMember("Shriya", 21, "S123", "Computer Science",


"T456",
"Python")

college_member.show_details()

#Multilevel Inheritance:
class Animal:
def __init__(self, name):
self.name = name

def eat(self):
print(f"{self.name} is eating.")

class Mammal(Animal):
def __init__(self, name, habitat):
super().__init__(name)
self.habitat = habitat

def give_birth(self):
print(f"{self.name} is a mammal and gives birth to live young.")

class Dog(Mammal):
def __init__(self, name, habitat, breed):
super().__init__(name, habitat)
self.breed = breed

def bark(self):
print(f"{self.name} ({self.breed}) is barking.")

dog = Dog("Buddy", "Domestic", "Golden Retriever")

dog.eat()
dog.give_birth()
dog.bark()

OUTPUT :

You might also like