Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aria_tuto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabrice ALLAIN
aria_tuto
Commits
a8c3ff3f
Commit
a8c3ff3f
authored
6 years ago
by
Fabrice ALLAIN
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
3dece1da
Branches
master
No related tags found
No related merge requests found
Pipeline
#9559
failed
6 years ago
Stage: build
Stage: test
Stage: production
Stage: performance
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Vehicle.py
+50
-0
50 additions, 0 deletions
Vehicle.py
with
50 additions
and
0 deletions
Vehicle.py
0 → 100644
+
50
−
0
View file @
a8c3ff3f
class
Vehicle
(
object
):
def
__init__
(
self
,
speed
=
0
):
self
.
speed
=
speed
self
.
odometer
=
0
self
.
time
=
0
def
say_state
(
self
):
print
(
"
I
'
m going {} kph!
"
.
format
(
self
.
speed
))
def
accelerate
(
self
):
self
.
speed
+=
5
def
brake
(
self
):
if
self
.
speed
<
5
:
self
.
speed
=
0
else
:
self
.
speed
-=
5
def
step
(
self
):
self
.
odometer
+=
self
.
speed
self
.
time
+=
1
def
average_speed
(
self
):
if
self
.
time
!=
0
:
return
self
.
odometer
/
self
.
time
else
:
pass
if
__name__
==
'
__main__
'
:
my_car
=
Car
()
print
(
"
I
'
m a car!
"
)
while
True
:
action
=
input
(
"
What should I do? [A]ccelerate, [B]rake,
"
"
show [O]dometer, or show average [S]peed?
"
).
upper
()
if
action
not
in
"
ABOS
"
or
len
(
action
)
!=
1
:
print
(
"
I don
'
t know how to do that
"
)
continue
if
action
==
'
A
'
:
my_car
.
accelerate
()
elif
action
==
'
B
'
:
my_car
.
brake
()
elif
action
==
'
O
'
:
print
(
"
The car has driven {} kilometers
"
.
format
(
my_car
.
odometer
))
elif
action
==
'
S
'
:
print
(
"
The car
'
s average speed was {} kph
"
.
format
(
my_car
.
average_speed
()))
my_car
.
step
()
my_car
.
say_state
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment