FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python3/samples/oop_basic/protected_student.py at master · sofay/learn-python3 · GitHub
sofay
/
learn-python3
Public
forked from
michaelliao/learn-python3
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python3
/
samples
/
oop_basic
/
protected_student.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
35 lines (27 loc) · 804 Bytes
Breadcrumbs
learn-python3
/
samples
/
oop_basic
/
protected_student.py
Copy path
File metadata and controls
executable file
·
35 lines (27 loc) · 804 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class
Student
(
object
):
def
__init__
(
self
,
name
,
score
):
self
.
__name
=
name
self
.
__score
=
score
def
get_name
(
self
):
return
self
.
__name
def
get_score
(
self
):
return
self
.
__score
def
set_score
(
self
,
score
):
if
0
<=
score
<=
100
:
self
.
__score
=
score
else
:
raise
ValueError
(
'bad score'
)
def
get_grade
(
self
):
if
self
.
__score
>=
90
:
return
'A'
elif
self
.
__score
>=
60
:
return
'B'
else
:
return
'C'
bart
=
Student
(
'Bart Simpson'
,
59
)
print
(
'bart.get_name() ='
,
bart
.
get_name
())
bart
.
set_score
(
60
)
print
(
'bart.get_score() ='
,
bart
.
get_score
())
print
(
'DO NOT use bart._Student__name:'
,
bart
.
_Student__name
)
Back
|
FazBrowse Home
|
New Git URL