Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding comments #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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())