Practical exam 02: PRP201c
120 minutes
Exercise 1: (3 marks)
Write a program that ask the user how many integers they want to generate. It should then generate that many integers randomly which is range from 1 to 100 and then store them in a list.
After the list is populated, the program will calculate and display the average of these numbers, and also display the smallest and highest value in the list.
Result of the program:
How many random integers would you like to generate? -5
Please enter a positive integer.
How many random integers would you like to generate? a
Invalid input. Please enter a positive integer.
How many random integers would you like to generate? 5
Generated list of integers: [60, 3, 66, 49, 62]
Average of the numbers: 48.00
Smallest number: 3
Largest number: 66
Exercise 2: (3 marks)
Write a program named count_word_occurrences that reads a text file named 'data_2.txt'. The program counts the occurrence of each unique word, then displays the number of occurrences of each word, and the word with the highest frequency.
The content of data 2 txt file
+ 100%
Zoom
Close