0% found this document useful (0 votes)
15 views12 pages

Python Built-in Functions & Inheritance Examples

The document contains multiple Kodin Code Session Reports by Utkarsh Pratap Singh, detailing various Python programming tasks including built-in functions documentation, inheritance concepts, mathematical operations, string manipulation, dictionary operations, and the use of classes and objects. Each report includes the question, aim, algorithm, solution code, program output, and conclusion for each task. Overall, the reports demonstrate the author's progress and understanding of Python programming concepts.
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)
15 views12 pages

Python Built-in Functions & Inheritance Examples

The document contains multiple Kodin Code Session Reports by Utkarsh Pratap Singh, detailing various Python programming tasks including built-in functions documentation, inheritance concepts, mathematical operations, string manipulation, dictionary operations, and the use of classes and objects. Each report includes the question, aim, algorithm, solution code, program output, and conclusion for each task. Overall, the reports demonstrate the author's progress and understanding of Python programming concepts.
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

Kodin Code Session Report - Utkarsh Pratap Singh

Date: 2025-10-05 [Link]

QUESTION
1. To write a Python program to print the documents (syntax, description, etc.) of Python
built-in Functions.

AIM
To print the documents of python built-in functions ,ex-abs, len ,sorted.

ALGORITHM
[Link]
[Link](built-in function.__doc__)
[Link]

SOLUTIONS
File: [Link]
print(abs.__doc__)
print(len.__doc__)
print(sorted.__doc__)

PROGRAM OUTPUT
Return the absolute value of the argument.
Return the number of items in a container.
Return a new list containing all items from the iterable in ascending order.A custom key
function can be supplied to customize the sort order, and the
reverse flag can be set to request the result in descending order.

CONCLUSION
I have got to know about some built-in functions of python.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-11-22 [Link]

QUESTION
10. Implement single, multiple, multi-level, and hybrid inheritance concepts using Python.

AIM
To implement single, multiple, multi-level, and hybrid inheritance concepts using Python.

ALGORITHM
start
"single inheritance": create a base class with a method.
create a derived class that extends it and call both methods using an object.
"multiple inheritance":create two parent classes with different methods.
create a child class inheriting both and access all methods using an object.
"multi-level inheritance":create a base class-> child class->grandchild class.
use the grandchild object to call methods from all three levels.
"hybrid inheritance":create a combination of hierarchical multiple inheritance .
define methods in each class and use the final derived class object to access all
inherited methods.
create objects for each inheritance type and display fixed values.
stop.

SOLUTIONS
File: [Link]
#SINGLE INHERITANCE
class Animal:
def sound(self):
print("Animal Sound: Generic Sound")
class Dog(Animal):
def type(self):
print("Dog Type: Labrador")
obj1 = Dog()
print("-----Single Inheritance:-----")
[Link]()
[Link]()
#MULTIPLE INHERITANCE
class Father:
def father_details(self):
print("Father Age: 45")
class Mother:
def mother_details(self):
print("Mother Age: 42")
class Child(Father,Mother):
def child_details(self):
print("Child Age: 18")
obj2 = Child()
print ("-----Multiple Inheritance:-----")
obj2.father_details()
obj2.mother_details()
obj2.child_details()
#MULTI-LEVEL INHERITANCE
class Country:
def country_name(self):
print("Country: India")
class State(Country):
def state_name(self):
print("State: Uttar Pradesh")
class City(State):
def city_name(self):
print("City: Lucknow")
obj3=City()
print("-----Multi-Level Inheritance:-----")
obj3.country_name()
obj3.state_name()
obj3.city_name()
#HYBRID INHERITANCE
class Vehicle:
def vehicle_type(self):
print("Vehicle Type: 4 Wheeler")
class Car(Vehicle):
def car_brand(self):
print("Car Brand: Hyundai")
class Electric:
def battery_capacitor(self):
print("Battery: 40kWh")
class ElectricCar(Car,Electric):
def model(self):
print("Model: Hyundai Kona")
obj4=ElectricCar()
print("-----Hybrid Inheritance:-----")
obj4.vehicle_type()
obj4.car_brand()
obj4.battery_capacitor()
[Link]()

PROGRAM OUTPUT
-----Single Inheritance:-----
Animal Sound: Generic Sound
Dog Type: Labrador
-----Multiple Inheritance:-----
Father Age: 45
Mother Age: 42
Child Age: 18
-----Multi-Level Inheritance:-----
Country: India
State: Uttar Pradesh
City: Lucknow
-----Hybrid Inheritance:-----
Vehicle Type: 4 Wheeler
Car Brand: Hyundai
Battery: 40kWh
Model: Hyundai Kona

CONCLUSION
I have successfully learned to implement different type of inheritance concepts using
Python.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-10-04 [Link]

QUESTION
2. To write a Python program to find the square root of a number.

AIM
To find the square root of a number.

ALGORITHM
[Link]
[Link] a variable n.
[Link] n = input by the user
[Link] n<0,print "there is no real root of n
[Link] print the square root of number is ,(n**0.5)
[Link]

SOLUTIONS
File: [Link]
n=int (input("Enter a number:"))
if (n<0):{
print("there is no real root of",n)
}
else:
{
print("the square root of the number is:",n**0.5)}

PROGRAM OUTPUT
Enter a number:256
the square root of the number is: 16.0

CONCLUSION
I have successfully wrote a python program to find the square root of a number .
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-10-04 [Link]

QUESTION
3. To write a Python program for exponentiation (power of a number). Take user input.

AIM
To find the power of a number given by the user.

ALGORITHM
[Link]
[Link] (a) as a number input from user
[Link] (e)as another input from user
[Link] "the number is",(a**e)
[Link]

SOLUTIONS
File: [Link]
a=int(input("Enter a number:"))
e=int(input("Enter the power of the number:"))
print ("The number is : ",a**e)

PROGRAM OUTPUT
Enter a number:2
Enter the power of the number:5
The number is : 32

CONCLUSION
I have successfully wrote a python program for exponentiation.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-10-05 [Link]

QUESTION
4. To write a Python program to calculate the length of a string without using in-built
functions.

AIM
To find length of a string .

ALGORITHM
[Link]
[Link] a string as input from user.
[Link] count = 0.
[Link] a loop to iterate through each character of the string.
[Link] count+=1
[Link] loop ends,print the value of count.
[Link]

SOLUTIONS
File: [Link]
s=input("enter a string :")
count = 0
for char in s:
count +=1
print("the length of string is:",count)

PROGRAM OUTPUT
enter a string :happy birthday
the length of string is: 14

CONCLUSION
I have successfully wote a python program to find the length of a string without using
in-built functions.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-10-05 [Link]

QUESTION
5. To write a Python program to find the maximum from a list of numberss without using
in-built function.

AIM
To find the maximum from a list.

ALGORITHM
[Link]
[Link] number of elements in list from user.
[Link] a empty list as numbers[].
[Link] elements of list as input from user and append in list.
[Link] first variable(numbers[0]) as maximum and store it in a variable max_num.
[Link] loop(numbers[1:])
if num>max_num
display max_num
[Link]

SOLUTIONS
File: solution .py
n=int (input("enter the number of elements: "))
numbers = []
for i in range (n):
element = int (input("enter the element:"))
[Link](element)
max_num=numbers[0]
for num in numbers[1:]:
if num>max_num:
max_num=num
print("the max element in the list is:",max_num)

PROGRAM OUTPUT
enter the number of elements:7
enter the element:444
enter the element:543
enter the element:674
enter the element:241
enter the element:976
enter the element:987
enter the element:999
the max element in the list is: 999

CONCLUSION
I have successfully wrote the python program for finding maximum from a list without using
an in-built function.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-09-30 [Link]

QUESTION
6. To write a Python program to demonstrate various ways of accessing the string- By using
Indexing (Both Positive and Negative)

AIM
to demonstrate the various ways of accessing the string(positive and negative indexing).

ALGORITHM

SOLUTIONS
File: solution .py
a='utkarsh'
a1 =a[3]
a2 =a[-4]
print("word at positive 3 indexing is :",a1)
print("word at negative 4 indexing is:",a2)

PROGRAM OUTPUT
word at positive 3 indexing is : a
word at negative 4 indexing is: a

CONCLUSION
I have successfully demonstrated the various ways of accesing the string.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-10-05 [Link]

QUESTION
7. Create a dictionary and apply the following Methods: 1) Print the dictionary items 2)
access items 3) use get() 4)change values 5) use len()

AIM
To use the various dictionary operations in python programming.

ALGORITHM
[Link]
[Link] a dictionary with some key-value pairs
[Link] the entire dictionary
[Link] specific items using keys
[Link] items using get() Method
[Link] a value for an existing key
[Link] len() to find the number of items in the dictionary
[Link] all results
[Link]

SOLUTIONS
File: [Link]
student={
"name":"Utkarsh",
"age":"18",
"course":"[Link] cse ",
"grade":"A"
}
print("dictionary items:",student)
print("student name :",student["name"])
print("student course :",student["course"])
print ("student age (using get):",[Link]("age"))
student["grade"]="A+"
print ("updated grade:",student["grade"])
print ("total number of items in dictionary:",len(student))

PROGRAM OUTPUT
dictionary items: {'name': 'Utkarsh', 'age': '18', 'course': '[Link] cse ', 'grade': 'A'}
student name : Utkarsh
student course : [Link] cse
student age (using get): 18
updated grade: A+
total number of items in dictionary: 4

CONCLUSION
I have successfully demonstrated the usage of various dictionary operations in Python.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-11-11 [Link]

QUESTION
Write a python program to double a given number and write a python program to add two
numbers using lambda ().

AIM
To write a python program to find double a number and sum of two numbers using lambda
function.

ALGORITHM
start
write lambda function for double the number
print
write lambda function for sum of two numbers
end

SOLUTIONS
File: [Link]
s=lambda a:2*a
s2=lambda a,b:a+b
print(s(4))
print(s2(4,6))

PROGRAM OUTPUT
8
10

CONCLUSION
I have successfully learned to find double ofa number and sum of numbers using lambda
function.
Kodin Code Session Report - Utkarsh Pratap Singh
Date: 2025-11-22 [Link]

QUESTION
9. Do as Following.
(i) Write a Python program to display ‘Welcome to DGU’ by using classes and objects.
(ii) Write a Python program to call data members and function using classes and objects.
(iii) Write a program to find the sum of two numbers using class and methods.
(iv) Write a program to read 3 subject marks and display pass or failed using class and
object.

AIM
To do the given tasks using classes and objects in python programming.

ALGORITHM
start
"for(i)":create a class that contain method to print the message "Welcome to DGU".
create an object and call the method.
"for(ii)":create a class with some data members and a method to print their values .
create aan object and use it to access the data members through the method.
"for(iii)":define a class that stores two numbers as data members.
include a method to add these numbers and display the sum.
create an object and call the method .
"for(iv)":create a class with 3 marks as data members .
take input for marks and create a method that checks if all marks are>=33;display PASS or
FAIL accordingly.
use objects of all classes to execute their respective methods.
stop.

SOLUTIONS
File: [Link]
#(i)
class Message:
def display(self):
print(" (i)Welcome to DGU")
obj=Message()
[Link]()
#(ii)
class Student:
def __init__(self):
[Link] ="Utkarsh"
def show(self):
print(" (ii)Student Name =",[Link])
obj=Student()
[Link]()
#(iii)
class Add:
def __init__(self,a,b):
self.a=a
self.b=b
def sum(self):
print(" (iii)Sum = ",self.a+self.b)
obj = Add(10,20)
[Link]()
#(iv)
class Result:
def __init__(self):
self.m1=int(input(" Enter mark 1:"))
self.m2=int(input(" Enter mark 2:"))
self.m3=int(input(" Enter mark 3:"))
def check(self):
if self.m1>=33 and self.m2>=33 and self.m3>=33:
print(" (iv) Result : PASS")
else:
print(" (iv)Result : FAIL")
obj = Result()
[Link]()

PROGRAM OUTPUT
(i)Welcome to DGU
(ii)Student Name = Utkarsh
(iii)Sum = 30
Enter mark 1:99
Enter mark 2:95
Enter mark 3:100
(iv) Result : PASS

CONCLUSION
I have successfully learned to use classes, methods and objects for different programs of
python programming.

You might also like