Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views4 pages

Python Practical

The document contains practical coding exercises demonstrating various programming concepts. It includes creating a dictionary from two lists, counting word frequency in a string, calculating the length of a list recursively, and defining a Sphere class with methods to calculate its diameter, circumference, and volume. Each practical is accompanied by code snippets and print statements to display the results.

Uploaded by

kavyaa
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)
2 views4 pages

Python Practical

The document contains practical coding exercises demonstrating various programming concepts. It includes creating a dictionary from two lists, counting word frequency in a string, calculating the length of a list recursively, and defining a Sphere class with methods to calculate its diameter, circumference, and volume. Each practical is accompanied by code snippets and print statements to display the results.

Uploaded by

kavyaa
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/ 4

Practical No 8

keys = ['apple', 'banana', 'cherry']


values = [1, 2, 3]
# Map the lists into a dictionary
mapped_dict = dict(zip(keys, values))
# Print the resulting dictionary
print(mapped_dict)
Practical No 9
def count_word_frequency(text):
text = text.lower()
words = text.split()
word_freq = {}
for word in words:
clean_word = ''.join(char for char in word if char.isalnum())
if clean_word:
word_freq[clean_word] = word_freq.get(clean_word, 0) + 1
return word_freq
input_string = "Hello world! Hello, OpenAI. OpenAI creates, OpenAI innovates."
frequency = count_word_frequency(input_string)
print(frequency)
Practical No 10
def recursive_length(lst):
if not lst:
return 0
else:
return 1 + recursive_length(lst[1:])
my_list = [10, 20, 30, 40, 50]
print("Length of the list:", recursive_length(my_list))
Practical No 11
import math
class Sphere:
def _init_(self, radius):
self.radius = radius
def diameter(self):
return 2 * self.radius
def circumference(self):
return 2 * math.pi * self.radius
def volume(self):
return (4/3) * math.pi * (self.radius ** 3)
radius = 5
sphere = Sphere(radius)
print("Diameter: {sphere.diameter()}")
print("Circumference: {sphere.circumference()}")
print("Volume: {sphere.volume()}")

You might also like