-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.py
More file actions
36 lines (31 loc) · 1.55 KB
/
student.py
File metadata and controls
36 lines (31 loc) · 1.55 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
35
36
# Code to create a Student class with attributes name, maths_score, science_score, english_score and a method averageScore to calculate the average score of the student and print the details of the student along with the average score
class Student:
def __init__(self, name, maths_score, science_score, english_score):
self.name = name
self.maths_score = maths_score
self.science_score = science_score
self.english_score = english_score
def averageScore(self):
average_score = (self.maths_score + self.science_score + self.english_score) / 3
print(f"Student Name: {self.name}")
print(f"Maths Score: {self.maths_score}")
print(f"Science Score: {self.science_score}")
print(f"English Score: {self.english_score}")
# print(f"Average Score: {average_score}")
return average_score
s1 = Student("Neha", 85, 90, 95)
print("Average Score:", s1.averageScore())
# Code to create a Student class with attributes name and marks (a list of marks in different subjects) and a method averageScore to calculate the average score of the student and print the details of the student along with the average score
class Student:
def __init__(self, name, marks):
self.name = name
self.marks = marks
def averageScore(self):
sum = 0
for mark in self.marks:
sum += mark
average = sum / len(self.marks)
print(f"Student Name: {self.name}")
return average
s1 = Student("Neha", [85, 90, 95])
print("Average Score:", s1.averageScore())