LAB-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):
[Link] = name
[Link] = usn
[Link] = []
[Link] = 0
[Link] = 0
def get_marks(self):
for i in range(3):
subject_marks = int(input(f"Enter the marks for subject {i+1}: "))
[Link](subject_marks)
[Link] += subject_marks
def display(self):
[Link] = [Link] / 3
print("Name:", [Link])
print("USN:", [Link])
print("Marks in subjects:", [Link])
print("Total marks:", [Link])
print("Percentage:", [Link])
# Taking student details from the user
name = input("Enter name: ")
usn = input("Enter USN: ")
# Creating student object
student = Student(name, usn)
student.get_marks()
[Link]()
Algorithm:
1. Start
2. Define a class Student:
• Attributes:
• name: to store the student's name.
• usn: to store the student's USN (University Serial Number).
• subjects: a list to store marks of 3 subjects.
• total: to store the sum of marks.
• percentage: to store the calculated percentage.
3. Define the __init__() method:
• Initialize name and usn with values passed during object creation.
• Initialize subjects as an empty list.
• Initialize total and percentage as 0.
4. Define the get_marks() method:
• For 3 times (loop from 0 to 2):
• Prompt the user to enter marks for each subject.
• Convert the input to integer and append it to subjects list.
• Add the marks to total.
5. Define the display() method:
• Calculate percentage as total / 3.
• Print student's name.
• Print student's USN.
• Print list of marks in subjects.
• Print total marks.
• Print percentage.
6. Main program:
• Prompt the user to input the student's name.
• Prompt the user to input the student's USN.
• Create an object of class Student with the name and USN.
• Call get_marks() method on the student object to input marks.
• Call display() method on the student object to display all details.
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