0% found this document useful (0 votes)
39 views4 pages

Python Lab Program 10

The document outlines a program that defines a Student class to manage student marks in three subjects. It includes methods for inputting marks, calculating total marks and percentage, and displaying the score card. The main program prompts for student details and utilizes the class to display the results.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Python Lab Program 10

The document outlines a program that defines a Student class to manage student marks in three subjects. It includes methods for inputting marks, calculating total marks and percentage, and displaying the score card. The main program prompts for student details and utilizes the class to display the results.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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):
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)

# Taking student details from the user


name = input("Enter name: ")
usn = input("Enter USN: ")

# Creating student object


student = Student(name, usn)
student.get_marks()
student.display()

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

You might also like