Introduction:
This Python code shows how to store records of students in a tuple and print them. Each record contains the student’s serial number, roll number, name, and marks.
Code:
#To store records of students in tuple and print them
st=((101,"Aman",98),(102,"Geet",95),(103,"Sahil",87),(104,"Pawan",79))
print("S_No"," Roll_No"," Name"," Marks")
for i in range(0,len(st)):
print((i+1),'\t',st[i][0],'\t',st[i][1],'\t',st[i][2])
Logic:
- Create a tuple called ‘st’ that contains the student records.
- Each record is represented as a tuple itself, with the serial number, roll number, name, and marks as elements.
- Print the header of the table, specifying the column names.
- Use a for loop to iterate through each record in the ‘st’ tuple.
- Inside the loop, print the serial number, roll number, name, and marks of each student.
Output:
>> S_No Roll_No Name Marks
>> 1 101 Aman 98
>> 2 102 Geet 95
>> 3 103 Sahil 87
>> 4 104 Pawan 79