Computer Science
Write a program that interactively creates a nested tuple to store the marks in three subjects for five students, i.e., tuple will look somewhat like :
marks( (45, 45, 40), (35, 40, 38), (36, 30, 38), (25, 27, 20), (10, 15, 20) )
Python
Python Tuples
11 Likes
Answer
num_of_students = 5
tup = ()
for i in range(num_of_students):
print("Enter the marks of student", i + 1)
m1 = int(input("Enter marks in first subject: "))
m2 = int(input("Enter marks in second subject: "))
m3 = int(input("Enter marks in third subject: "))
tup = tup + ((m1, m2, m3),)
print()
print("Nested tuple of student data is:", tup)
Output
Enter the marks of student 1
Enter marks in first subject: 89
Enter marks in second subject: 78
Enter marks in third subject: 67
Enter the marks of student 2
Enter marks in first subject: 56
Enter marks in second subject: 89
Enter marks in third subject: 55
Enter the marks of student 3
Enter marks in first subject: 88
Enter marks in second subject: 78
Enter marks in third subject: 90
Enter the marks of student 4
Enter marks in first subject: 78
Enter marks in second subject: 67
Enter marks in third subject: 56
Enter the marks of student 5
Enter marks in first subject: 45
Enter marks in second subject: 34
Enter marks in third subject: 23
Nested tuple of student data is: ((89, 78, 67), (56, 89, 55), (88, 78, 90), (78, 67, 56), (45, 34, 23))
Answered By
6 Likes
Related Questions
Write a program to input n numbers from the user. Store these numbers in a tuple. Print the maximum and minimum number from this tuple.
Write a program to create a nested tuple to store roll number, name and marks of students.
Write a program that interactively creates a nested tuple to store the marks in three subjects for five students and also add a function that computes total marks and average marks obtained by each student.
Tuple will look somewhat like :
marks( (45, 45, 40), (35, 40, 38),(36, 30, 38), (25, 27, 20), (10, 15, 20) )Write a program that inputs two tuples and creates a third, that contains all elements of the first followed by all elements of the second.