Page 198 - Information_Practice_Fliipbook_Class11
P. 198
06 result: list of lists of result of all students
07 '''
08
09 classResult = []
10 nStudents = int(input('Enter number of students: '))
11 print('Enter the list [Roll No, Marks] and press enter: ')
12 for i in range(0, nStudents):
13 #Enter student result as a list: [rollNo, marks]
14 result = eval(input('[rollNo, marks]: '))
15 classResult.append(result)
16
17 #Update result
18 #Accept roll number and updated marks interactively
19 print('Continue to update the result?')
20 moreUpdates = input('Say Y/y for yes, N/n for no:')
21
22 while moreUpdates == 'Y' or moreUpdates == 'y':
23 rollNo = int(input('Enter roll no for marks update: '))
24 marks = int(input('Enter revised marks for update: '))
25 for indx in range(len(classResult)):
26 #look for rollNo in each subslist
27 if(classResult[indx][0] == rollNo):
28 classResult[indx][1] = marks
29 break
30 print('Continue another update?')
31 moreUpdates = input('Say Y/y for yes, N/n for no:')\
32
33 #Display results
34 print('Moderated result:')
35 print(classResult)
Sample output:
>>> Enter number of students: 4
>>> Enter the list [Roll No, Marks] and press enter:
[rollNo, marks]: [501, 66]
[rollNo, marks]: [503, 55]
[rollNo, marks]: [504, 46]
[rollNo, marks]: [505, 30]
Continue to update the result?
Say Y/y for yes, N/n for no:y
>>> Enter roll no for marks update: 505
>>> Enter revised marks for update: 33
Continue another update?
Say Y/y for yes, N/n for no:y
>>> Enter roll no for marks update: 501
>>> Enter revised marks for update: 60
Continue another update?
Say Y/y for yes, N/n for no:n
Moderated result:
[[501, 60], [503, 55], [504, 46], [505, 33]]
Program 7.4 Write a program that accepts as input a list from a user and displays the list without duplicates.
01 '''
02 Objective: To remove duplicate from a list
03 Input: list with duplicate elements
04 Output: A list without duplicate elements
05 '''
06 myList = eval(input('Enter the list:\n'))
07 print('Original List:' , myList)
184 Touchpad Informatics Practices-XI

