The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is stored in the following list: stRecord = ['Raman','A-36', [56,98,99,72,69], 78.8] Write Python statements to retrieve the following information from the list stRecord. a) Percentage of the student b) Marks in the fifth subject c) Maximum marks of the student d) Roll no. of the student e) Change the name of the student from 'Raman' to 'Raghav'
Question
The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is stored in the following list:
stRecord = ['Raman','A-36', [56,98,99,72,69], 78.8]
Write Python statements to retrieve the following information from the list stRecord
.
a) Percentage of the student
b) Marks in the fifth subject
c) Maximum marks of the student
d) Roll no. of the student
e) Change the name of the student from 'Raman' to 'Raghav'
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
# Given student record
stRecord = ['Raman', 'A-36', [56, 98, 99, 72, 69], 78.8]
# a) Percentage of the student
percentage = stRecord[3]
print("Percentage of the student:", percentage)
# b) Marks in the fifth subject
marks_fifth_subject = stRecord[2][4]
print("Marks in the fifth subject:", marks_fifth_subject)
# c) Maximum marks of the student
max_marks = max(stRecord[2])
print("Maximum marks of the student:", max_marks)
# d) Roll no. of the student
roll_no = stRecord[1]
print("Roll no. of the student:", roll_no)
# e) Change the name of the student from 'Raman' to 'Raghav'
stRecord[0] = 'Raghav'
print("Updated student record:", stRecord)
Output:
Percentage of the student: 78.8
Marks in the fifth subject: 69
Maximum marks of the student: 99
Roll no. of the student: A-36
Updated student record: ['Raghav', 'A-36', [56, 98, 99, 72, 69], 78.8]
Explanation:
a) To retrieve the percentage, access the fourth element of the list
stRecord[3]
.b) To retrieve the marks in the fifth subject, access the fifth element of the nested list
stRecord[2][4]
.c) To retrieve the maximum marks, use the
max()
function on the nested liststRecord[2]
.d) To retrieve the roll number, access the second element of the list
stRecord[1]
.e) To change the name from 'Raman' to 'Raghav', update the first element of the list
stRecord[0]
.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month