Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
177 views

Program 1 Read a text file and display the number of vowels

Uploaded by

Namita Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

Program 1 Read a text file and display the number of vowels

Uploaded by

Namita Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Program 1 Read a text file and display the number of

vowels/consonants/uppercase/lowercase characters in the file.


Actual text file
Output:
Program 2 Create a binary file with name and roll no. Search for a
given roll number and display the name, if not found display
appropriate message.
Output:
Program 3 Write a python program to implement a stack using a list
data structure.
Stack Concept:

Output:

Program 14 def read_file(filename):


"""Read the contents of a file and return it as a string."""
with open(filename, 'r') as file:
return file.read()

def count_words(text):
"""Count the frequency of each word in the text."""
words = text.split()
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count

def get_most_common_words(word_count, num_words=10):


"""Return the most common words in the word count dictionary."""
sorted_words = sorted(word_count.items(), key=lambda item:
item[1], reverse=True)
return sorted_words[:num_words]

def main():
filename = 'phishing_emails.txt' # Change this to the path of your
text file
text = read_file(filename)
word_count = count_words(text)
most_common_words = get_most_common_words(word_count)

print("Most common words:")


for word, count in most_common_words:
print(f"{word}: {count}")

if __name__ == "__main__":
main()Program 15 Read a text file line by line and display each word
separated by a #
Output:

Program 16 Create a student table and insert data. Implement the


following SQL commands on the student table:
ALTER table to add new attributes / modify data type / drop attribute
UPDATE table to modify data
ORDER By to display data in ascending / descending order
DELETE to remove tuple(s)
GROUP BY and find the min, max, sum, count and average
Program 17:Integrate SQL with Python by importing the MySQL module
Program 18:Integrate SQL with Python by importing the pymysql
module

You might also like