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

Student Marks Calculation Program

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)
38 views4 pages

Student Marks Calculation Program

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

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

Common questions

Powered by AI

To efficiently handle varying numbers of subjects, the Student class could be modified to accept the number of subjects as an additional parameter during initialization and store it as an attribute. The get_marks() method could be adapted to loop dynamically based on this attribute. Similarly, the percentage calculation in the display() method could be adjusted to divide the total marks by the actual number of subjects instead of a hard-coded number. Such changes would allow the class to remain flexible and adaptable to different academic structures .

The example output for Ralph with USN '1XY24ABC001' verifies the implemented logic of the Student class by demonstrating the initialization of a Student object, the iterative collection of marks, cumulative total computation, and percentage calculation. With entered marks [50, 50, 48], the program correctly sums them to 148 and averages to approximately 49.33%, accurately displaying all calculated and initialized values per the logic defined in the methods, confirming program functionality as expected .

Using a list to store subject marks in the Student class design allows for dynamic scalability and convenient management of marks for multiple subjects. This structure enables easy iteration over marks for cumulative operations, such as totaling or averaging. It supports flexible expansion, should the number of subjects change, with minimal modification needed in the existing code. Lists also facilitate efficient storage and retrieval, essential for systematic processing of each student's data .

Calculating percentage by simple division assumes uniformity in subject weightage, potentially misrepresenting results if subjects have varied importances or mark ranges. This method also outputs a lengthy decimal, which may not be user-friendly. To address these, one could introduce logic to assign weights to each subject or use a standard mark conversion system. Additionally, the calculation could be rounded to two decimal places for clarity and precision in the displayed output .

The __init__() method in the Student class acts as a constructor to initialize an object's state upon creation. It receives the student's name and USN as parameters and sets them as object attributes. Additionally, it initializes 'subjects' as an empty list to later store marks, and 'total' and 'percentage' as zero, preparing the object for subsequent data computation through the get_marks() and display() methods. This initialization ensures that each Student object starts with a clean slate of attributes tailored for each instance .

The main program interacts with the user by prompting for the student's name and USN, and iteratively asking for marks for three subjects. Validity is assumed but not enforced since the program does not include validation checks to ensure correct data entries such as integer values for marks. Improving the input validity could include adding error handling to catch non-integer inputs and prompt the user to re-enter them, enhancing robustness and user-friendliness .

The percentage is calculated in the display() method by dividing the total marks by 3, assuming there are three subjects and that each subject's maximum possible marks are equivalent. The assumption is that the user inputs valid integer marks for each subject, and the total is simply the sum of these three integers. The percentage is then printed as a simple average of these marks .

Encapsulation in the Student class is illustrated by bundling data (student's name, USN, and marks) and methods (to manipulate that data) into one unit, the Student object. By using an __init__() method to initialize attributes and separate methods for data input (get_marks()) and output (display()), the class restricts direct access to attributes, enforcing interaction through its methods. It ensures organized and controlled access to the object's data and behavior .

Abstraction in the Student class separates complex realities of input gathering, data processing, and output display into simplified, well-defined methods—get_marks() and display(). This concealment of internal operations from the user and exposure of only necessary interactions (method calls) minimizes complexity and fosters easier maintenance and scalability. By abstracting and separating functionalities, the program stays organized, making it easier to debug and adapt over time without altering the underlying structure .

The Student class fosters code reuse and modularity by encapsulating properties and behaviors typical to student data management, offering a structured template to hold details, calculate scores, and display information without requiring redefinition in each use case. This class can be easily integrated across various programs that handle student data, ensuring consistency and reducing redundancy in codebase through its modular design .

You might also like