-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10.py
More file actions
34 lines (29 loc) · 1.24 KB
/
10.py
File metadata and controls
34 lines (29 loc) · 1.24 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
33
34
#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 = 0
def getMarks(self):
print("Enter marks in three subjects:")
for i in range(3):
marks = float(input(f"Subject {i+1}: "))
self.marks.append(marks)
self.total += marks
def display(self):
percentage = self.total / 3
print("Score Card:")
print(f"Name: {self.name.upper()}")
print(f"USN: {self.USN.upper()}")
print(f"Marks: {self.marks}")
print(f"Total: {self.total}")
print(f"Percentage: {percentage}")
name = input("Enter the name of the student: ")
USN = input("Enter the USN of the student: ")
student = Student(name, USN)
student.getMarks()
student.display()