Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbea25a

Browse files
committed
add class definition
1 parent fe13d54 commit dbea25a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

py3/oop_basic/student.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
class Student(object):
5+
6+
def __init__(self, name, score):
7+
self.name = name
8+
self.score = score
9+
10+
def print_score(self):
11+
print('%s: %s' % (self.name, self.score))
12+
13+
def get_grade(self):
14+
if self.score >= 90:
15+
return 'A'
16+
elif self.score >= 60:
17+
return 'B'
18+
else:
19+
return 'C'
20+
21+
bart = Student('Bart Simpson', 59)
22+
lisa = Student('Lisa Simpson', 87)
23+
24+
print('bart.name =', bart.name)
25+
print('bart.score =', bart.score)
26+
bart.print_score()
27+
28+
print('grade of Bart:', bart.get_grade())
29+
print('grade of Lisa:', lisa.get_grade())

0 commit comments

Comments
 (0)