Page 301 - Computer Science Class 11 Without Functions
P. 301

Count of 9 in list is: 1
            Updating Marks in an Examination

            Program 12.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 result needs to be updated and

                update the list result.
            5.  Displays the result 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:
              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)
            Below we give the output of a sample run of the program.

            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?


                                                                                                Lists and Tuples  299
   296   297   298   299   300   301   302   303   304   305   306