-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassover.py
More file actions
32 lines (27 loc) · 1.08 KB
/
classover.py
File metadata and controls
32 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Define a class Student in Python with attributes to store the roll number, name, and marks of three subjects for each student.
# Define the following methods:
# readdata() - to assign values to the attributes
# computetotal() - to find the total marks
# printdetails() - to display the attribute values and the total marks
# Create an object of the class and invoke all the methods.
class Student:
def __init__(self):
self.roll_number = None
self.name = None
self.marks = []
self.total_marks = 0
def readdata(self):
self.roll_number = input("Enter Roll Number: ")
self.name = input("Enter Name: ")
self.marks = [int(input(f"Enter marks for subject {i+1}: ")) for i in range(3)]
def computetotal(self):
self.total_marks = sum(self.marks)
def printdetails(self):
print(f"Roll Number: {self.roll_number}")
print(f"Name: {self.name}")
print(f"Marks: {self.marks}")
print(f"Total Marks: {self.total_marks}")
student1 = Student()
student1.readdata()
student1.computetotal()
student1.printdetails()