2023-24-Part-1-Python-Lab Manual python-DVD
2023-24-Part-1-Python-Lab Manual python-DVD
Experiment No - 10
Problem Description: When it is required to find the length of a list with the help
of recursion technique, a user defined method is used, and simple indexing
technique is used.
Problem Solution:
method named ‘Recur’ is defined, that takes a list as a parameter.
If the list is not present, the method returns 0.
Otherwise, it is indexed, and incremented by 1 and returned as output.
It will ask to enter a list
List will be splited by using ‘split’ function
Outside the function, a list is defined, and is displayed on the console.
The method is called by passing this list as a parameter.
The output is then displayed on the console.
1. What is Recursion?
2. What is Slicing?
3. What is Indexing?
4. If we are not writing any return in the given function then while printing the
function what will be the corresponding output
Experiment No - 11
Problem Solution:
1. Define the radius of the sphere
2. Define the pie and assign (22/7)
3. Calculate the volume of the sphere as (4/3)*pie*r3
4. Assign the volume of the sphere to volume_of_sphere
5. Print the volume of the sphere.
Experiment No – 11
Program:
class sphere:
def _init_(self):
print("object created")
obj=sphere()
radius=float(input("Enter Radius= "))
pi=3.14
diameter=2*radius
print("Diameter is= ",diameter)
volume=4/3*pi*radius*radius*radius
print("volume is=",volume)
Output:
object created
Enter Radius= 5
Diameter is= 10
volume is= 523.3333333333334
Experiment No - 12
Program to read a file and capitalize the first letter of every word in
the file.
Problem Description
The program reads a file and capitalizes the first letter of every word in
the file.
Problem Solution
1. Take the file name from the user.
2. Read each line from the file and use the title() function to capitalize
each word in the line.
3. Print the altered lines of the file.
5. Exit.