Define a class Student that keeps tracks of academic record of students in a school.
The class should contain the following data members:
rollNum Roll number of student
name Name of student
marks- Total Marks of student (considering 500 as maximum marks)
stream- 'A': Arts, 'C': Commerce, 'S': Science
percent- Percentage computed using Marks
The class should support the following methods:
To define the Student
class that tracks the academic record of students in a school, we will include the following data members and methods:
rollNum
: Roll number of the student.name
: Name of the student.marks
: Total marks obtained by the student (out of 500).stream
: Stream of the student, which can be 'A' (Arts), 'C' (Commerce), or 'S' (Science).percent
: Percentage of the student, computed using the marks.__init__(self, rollNum, name, marks, stream)
: Constructor method to initialize the student’s data.calculate_percentage(self)
: Method to calculate and store the percentage based on marks.display_details(self)
: Method to display the student's details, including roll number, name, stream, marks, and percentage.grade(self)
: Method to determine and return the grade based on the percentage.class Student:
# Constructor to initialize student data
def __init__(self, rollNum, name, marks, stream):
self.rollNum = rollNum # Student's roll number
self.name = name # Student's name
self.marks = marks # Total marks obtained by the student
self.stream = stream # Stream: 'A', 'C', or 'S'
self.percent = 0 # Initialize percentage to 0 initially
# Method to calculate percentage
def calculate_percentage(self):
self.percent = (self.marks / 500) * 100 # Percentage = (marks/total marks) * 100
# Method to display student's details
def display_details(self):
# Displaying all details of the student
print(f"Roll Number: {self.rollNum}")
print(f"Name: {self.name}")
print(f"Stream: {self.stream}")
print(f"Total Marks: {self.marks}")
print(f"Percentage: {self.percent}%")
# Method to calculate grade based on percentage
def grade(self):
if self.percent >= 80:
return "A"
elif self.percent >= 60:
return "B"
elif self.percent >= 45:
return "C"
else:
return "D"
# Example usage:
# Create a student object
student1 = Student(101, "John Doe", 450, "S")
# Calculate the percentage
student1.calculate_percentage()
# Display student details
student1.display_details()
# Get and print the grade
print("Grade:", student1.grade())
__init__
(Constructor):
Student
object is created.calculate_percentage
:
display_details
:
grade
:
Roll Number: 101
Name: John Doe
Stream: S
Total Marks: 450
Percentage: 90.0%
Grade: A
Student
object by providing roll number, name, marks, and stream.calculate_percentage()
method to compute the percentage.display_details()
method to print the student's details.grade()
method to determine and print the student's grade based on their percentage.This program covers all the basic functionalities as requested, allowing you to track and calculate academic details for students.
Answered By