Python Lab Programs
Python Lab Programs
Output:
Keys List: ['name', 'age', 'city']
Values List: ['Srishti', 20, 'Mumbai']
Mapped Dictionary: {'name': 'Srishti', 'age': 20, 'city': 'Mumbai'}
Program 2: Word Frequency Using Dictionary
sentence = input("Enter a sentence: ")
words = [Link]()
freq = {}
print(freq)
Output:
Enter a sentence: python is easy and python is fun
{'python': 2, 'is': 2, 'easy': 1, 'and': 1, 'fun': 1}
Program 3: Dictionary with First Character as Key
words = ["apple", "banana", "ball", "cat", "car"]
result = {}
print(result)
Output:
{'a': ['apple'], 'b': ['banana', 'ball'], 'c': ['cat', 'car']}
Program 4: Length of List Using Recursion
def list_length(lst):
if lst == []:
return 0
return 1 + list_length(lst[1:])
Output:
Length of list: 5
Program 5: Compute Diameter, Circumference and Volume of Sphere Using
Class
import math
class Sphere:
def __init__(self, radius):
[Link] = radius
def diameter(self):
return 2 * [Link]
def circumference(self):
return 2 * [Link] * [Link]
def volume(self):
return (4/3) * [Link] * [Link]**3
Output:
Enter radius: 7
Diameter = 14
Circumference = 43.98
Volume = 1436.75
Program 6: Read a File and Capitalize First Letter of Every Word
file = open("[Link]", "r")
content = [Link]()
[Link]()
capitalized_text = [Link]()
print("Original Content:")
print(content)
print("After Capitalization:")
print(capitalized_text)
Output:
Original Content:
python is a programming language
After Capitalization:
Python Is A Programming Language