-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (52 loc) · 1.37 KB
/
Copy pathmain.py
File metadata and controls
69 lines (52 loc) · 1.37 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# """
# def hello():
# print("hello")
# x = 1
# print(type(hello))
# x=1
# y=2
# print(x+y)
# string = "hello"
# print(string.upper())
# """
# class Dog:
# def __init__(self, name, age):
# self.name = name
# self.age = age
# def get_name(self):
# return self.name
# def get_age(self):
# return self.age
# def set_age(self,age):
# self.age = age
class Student:
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade # 0 to 100
def get_grade(self):
return self.grade
class Course:
def __init__(self, name, max_students):
self.name = name
self.max_students = max_students
self.students = []
self.is_active = False
def add_student(self, student):
if len(self.students)<self.max_students:
self.students.append(student)
return True
return False
def get_average_grade(self):
value = 0
for student in self.students:
value += student.get_grade()
return value / len(self.students)
s1 = Student("Tim", 19, 95)
s2 = Student("Bill", 19, 75)
s3 = Student("Jill", 19, 65)
course = Course("Science", 2)
course.add_student(s1)
course.add_student(s2)
print(course.add_student(s3))
print(course.get_average_grade())