BASIC PYTHON TEST
You are given a text file grades.txt where each line contains a student's name and their scores in
multiple subjects, separated by commas.
Example file content:
Alice,88,76,92
Bob,90,85,79
Charlie,95,80,85
Task:
• Read the file and store the data in a dictionary where the key is the student's name, and the
value is a list of their scores.
• Write a function calculate_average(grades: list) -> float to calculate the average.
• Display each student’s name along with their average score.
Bonus:
• Write the result to a new file averages.txt in this format:
Alice: 85.33
Bob: 84.67
Charlie: 86.67
Question 2: Word Frequency Counter
Problem Statement:
Write a program that reads a text file input.txt and calculates the frequency of each word in the file.
Task:
• Use a dictionary to count how many times each word appears (ignore punctuation and case).
• Use a function get_word_frequency(filename: str) -> dict that returns the frequency
dictionary.
• Sort and print the top 5 most frequent words.
Bonus:
• Save the frequency dictionary into a new file frequency.txt in descending order.