App Lab Expt 6
App Lab Expt 6
10, 11, 11, 13, 13, 15, 16, 17, 18, 18,
18, 19, 20, 21, 21, 23, 24, 24, 25, 25,
25, 25, 26, 26, 26, 27, 27, 27, 27, 27,
29, 30, 30, 31, 33, 34, 34, 34, 35, 36,
36, 37, 37, 38, 38, 39, 40, 41, 41, 42,
43, 44, 45, 45, 46, 47, 48, 48, 49, 50,
51, 52, 53, 54, 55, 55, 56, 57, 58, 60,
61, 63, 64, 65, 66, 68, 70, 71, 72, 74,
75, 77, 81, 83, 84, 87, 89, 90, 90, 91
]
plt.hist(x, bins=5)
plt.show()
output:
a) Read text from a file and print the number of lines, words and characters
D:\Sree>python 6a.py
Enter a file name : file.txt
['Computer science Engineering\n', 'Elecronics and Communication Engineering\n', 'Civil Engineering\n']
The number of Characters are : 88
The number of Words are : 9
The number of Lines are : 3
b) Read text from a file and return a list of all n letter words beginning with a vowel
Program:
file1 = open("file.txt", "r")
data = file1.read()
words = data.split()
list1 = []
for i in words:
if i[0] in "aeiouAEIOU":
list1.append(i)
print(list1)
file1.close()
output:
d) Plot a histogram of words according to their length from text read from a file
Program:
from collections import Counter
import numpy as np
import matplotlib.pyplot as plt
full = "hi hello well come to computer science and engineering electronics and communication engineering all the best"
x=list(full)
labels, values = zip(*Counter(x).items())
indexes = np.arange(len(labels))
width = 1
output: