Page 197 - Information_Practice_Fliipbook_Class11
P. 197
Program 7.2: Write a program that accepts a list of integers and displays the frequency of each element in the list.
01 '''
02 Objective: To count the frequency of each element in mylist
03 User Interface:
04 User is asked to enter:
05 number of elements in the list
06 list elements one by one
07 '''
08 myList = []
09 numElements = int(input('Enter size of the list: '))
10 print('Enter each element and press enter: ')
11 for i in range(0, numElements): #list input element-wise
12 num = int(input())
13 myList.append(num)
14 print('Contents of list:', myList)
15 uniqueMyList = set(myList)
16 for item in uniqueMyList:
17 print(f'Count of {item} in list is: {myList.count(item)}')
Sample output:
>>> Enter size of the list: 10
>>> Enter each element and press enter:
3
7
1
3
9
1
8
2
8
1
Contents of list: [3, 7, 1, 3, 9, 1, 8, 2, 8, 1]
Count of 1 in list is: 3
Count of 2 in list is: 1
Count of 3 in list is: 2
Count of 7 in list is: 1
Count of 8 in list is: 2
Count of 9 in list is: 1
Updating Marks in an Examination
Program 7.3 Write a program that manages the results of students in an examination.
It performs the following tasks:
1. Accepts the number of students from the user.
2. Accepts the result of each student from the user in the form of a list [rollNo, marks].
3. Constructs the list result comprising the list [rollNo, marks] from step 2, for each student.
4. Accept from the user interactively roll number and marks of students whose results need to be updated and
update the list result.
5. Displays the results of all the students.
01 '''
02 objective:
03 (1) To read result of all students
04 (2) To update result of all students
05 Global data:
Python Lists 183

