-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcargame.py
More file actions
29 lines (27 loc) · 1.05 KB
/
cargame.py
File metadata and controls
29 lines (27 loc) · 1.05 KB
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
#short car game to get used to python!
command = ''
started = False
while True:
command = input('> ').lower()
if command == 'help':
print('''
start - car started
stop - car stopped
quit - game over
''')
elif command == 'start':
if started == False: # initial set condition is False so when start commend is given python checks if variable started is false
started = True # if yes then it is changed to true and 'car started'is printed
print('car started')
else:
print('car already started') # otherwise if it is true then else instructions are followed, same happens for stop command
elif command == 'stop':
if not started: # here also python checks started is false, equivalent started == False (comparison)
print('car already stopped')
else:
started = False
print('car stopped')
elif command == 'quit':
break
else:
print('I do not understand')