-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastDraw.py
More file actions
37 lines (33 loc) · 1.29 KB
/
fastDraw.py
File metadata and controls
37 lines (33 loc) · 1.29 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
30
31
32
33
34
35
36
37
import random, sys, time
print('Fast Draw, by Al Sweigat al@inventwithpython.com')
print()
print('Time to test your reflexes an see if youare the fastest')
print('draw in the west!')
print('When you see "DRAW", you have 0.3 seconds to press Enter.')
print('But you lose if you press Enter before "Draw" appears.')
print()
# input('Press Enter to begin....')
while True:
print()
print('It is high noon...')
time.sleep(random.randint(20, 50)/ 10.0)
print('DRAW!')
drawTime = time.time()
input() #This function call doesn't return until Enter is pressed.
timeElapsed = time.time() - drawTime
if timeElapsed < 0.01:
# if the player pressed Enter before DRAW! apperared, the input()
# call returns almost instantly.
print('You drew before "DRAW" appeared! You lose.')
elif timeElapsed > 0.3:
timeElapsed = round(timeElapsed, 4)
print('You took', timeElapsed, 'seconds to draw. Too slow!')
else:
timeElapsed = round(timeElapsed, 4)
print('You took', timeElapsed, 'seconds to draw.')
print('You are the fastest draw in the west! You win!')
print('Enter QUIT to stop, or press Enter to play again.')
response = input('> ').upper()
if response == 'QUIT':
print('Thanks for playing!')
sys.exit()