forked from jwasham/practice-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit_test.py
More file actions
29 lines (24 loc) · 738 Bytes
/
bit_test.py
File metadata and controls
29 lines (24 loc) · 738 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
import random
def bit_test():
keep_going = True
while keep_going:
rand_num = random.randint(0, 0xFF)
bits = bin(rand_num)
correct = False
attempts = 1
while not correct:
answer = input('What is {} in decimal? '.format(bits.replace('0b', '').rjust(8, '0')))
attempts += 1
if int(answer) == rand_num:
print('*** Correct! ***')
correct = True
else:
if attempts > 3:
print('The answer is: {}'.format(rand_num))
correct = True
else:
print('Try again.')
def main():
bit_test()
if __name__ == '__main__':
main()