Python Lab Program 10
Python Lab Program 10
Develop a program that uses class Student which prompts the user to enter
marks in three subjects and calculates total marks, percentage and displays the
score card details. [Hint: Use list to store the marks in three subjects and total
marks. Use __init__() method to initialize name, USN and the lists to store
marks and total, Use getMarks() method to read marks into the list, and
display() method to display the score card details.]
class Student:
def __init__(self, name, usn):
self.name = name
self.usn = usn
self.subjects = []
self.total = 0
self.percentage = 0
def get_marks(self):
for i in range(3):
subject_marks = int(input(f"Enter the marks for subject {i+1}: "))
self.subjects.append(subject_marks)
self.total += subject_marks
def display(self):
self.percentage = self.total / 3
print("Name:", self.name)
print("USN:", self.usn)
print("Marks in subjects:", self.subjects)
print("Total marks:", self.total)
print("Percentage:", self.percentage)
Algorithm:
1. Start
2. Define a class Student:
• Attributes:
• name: to store the student's name.
• Initialize name and usn with values passed during object creation.
7. End
Output:
Enter name: Ralph
Enter USN: 1XY24ABC001
Enter the marks for subject 1: 50
Enter the marks for subject 2: 50
Enter the marks for subject 3: 48
Name: Ralph
USN: 1XY24ABC001
Marks in subjects: [50, 50, 48]
Total marks: 148
Percentage: 49.333333333333336