-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathstudent.py
More file actions
executable file
·38 lines (31 loc) · 847 Bytes
/
student.py
File metadata and controls
executable file
·38 lines (31 loc) · 847 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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):
"""
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:
return 'B'
else:
return 'C'
bart = Student('Bart Simpson', 59)
lisa = Student('Lisa Simpson', 87)
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())