0% found this document useful (0 votes)
4 views

Lab Program 9

The document provides an example of a program that prompts a user to enter marks in three subjects for a student. It uses a Student class to initialize attributes like name, USN, and lists to store marks and totals. Methods like getMarks() read in marks and display() prints the scorecard details.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab Program 9

The document provides an example of a program that prompts a user to enter marks in three subjects for a student. It uses a Student class to initialize attributes like name, USN, and lists to store marks and totals. Methods like getMarks() read in marks and display() prints the scorecard details.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

9.

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.marks = []

self.total_marks = 0

self.percentage = 0.0

def getMarks(self):

for i in range(3):

mark = float(input(f"Enter marks for subject {i+1}: "))

self.marks.append(mark)

self.total_marks += mark

self.percentage = self.total_marks / 3

def display(self):

print("-------- Score Card --------")

print("Name:", self.name)

print("USN:", self.usn)

print("Marks:", self.marks)

print("Total Marks:", self.total_marks)

print("Percentage:", self.percentage)
name = input("Enter student name: ")

usn = input("Enter student USN: ")

student = Student(name, usn)

student.getMarks()

student.display()

You might also like