Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions samples/oop_basic/student.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Student(object):
class Student:
"""
Represents a student with a name and score.
"""

def __init__(self, name, score):
self.name = name
self.score = score

def print_score(self):
print('%s: %s' % (self.name, self.score))
"""
Prints the student's name and score.
"""
print(f'{self.name}: {self.score}')

def get_grade(self):
"""
Returns the grade based on the student's score.
"""
if self.score >= 90:
return 'A'
elif self.score >= 60:
Expand All @@ -21,9 +30,9 @@ def get_grade(self):
bart = Student('Bart Simpson', 59)
lisa = Student('Lisa Simpson', 87)

print('bart.name =', bart.name)
print('bart.score =', bart.score)
print('bart.name:', bart.name)
print('bart.score:', bart.score)
bart.print_score()

print('grade of Bart:', bart.get_grade())
print('grade of Lisa:', lisa.get_grade())
print('Grade of Bart:', bart.get_grade())
print('Grade of Lisa:', lisa.get_grade())