CBSE Class 11 Computer Science Question 102 of 114

Tuples — Question 5

Back to all questions
5
Question

Question 4

Write a program to create a nested tuple to store roll number, name and marks of students.

Solution
tup = ()

ans = "y"
while ans == "y" or ans == "Y" :
      roll_num = int(input("Enter roll number of student: "))
      name = input("Enter name of student: ")
      marks = int(input("Enter marks of student: "))
      tup += ((roll_num, name, marks),)
      ans = input("Do you want to enter more marks? (y/n): ")
print(tup)
Output
Enter roll number of student: 1
Enter name of student: Shreya Bansal
Enter marks of student: 85
Do you want to enter more marks? (y/n): y
Enter roll number of student: 2
Enter name of student: Nikhil Gupta
Enter marks of student: 78
Do you want to enter more marks? (y/n): y
Enter roll number of student: 3
Enter name of student: Avni Dixit
Enter marks of student: 96
Do you want to enter more marks? (y/n): n
((1, 'Shreya Bansal', 85), (2, 'Nikhil Gupta', 78), (3, 'Avni Dixit', 96))
Answer