We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fe1f4cc commit d9e3412Copy full SHA for d9e3412
experiments/bit_test.py
@@ -0,0 +1,29 @@
1
+import random
2
+
3
4
+def bit_test():
5
+ keep_going = True
6
+ while keep_going:
7
+ rand_num = random.randint(0, 0xFF)
8
+ bits = bin(rand_num)
9
+ correct = False
10
+ attempts = 1
11
+ while not correct:
12
+ answer = input('What is {} in decimal? '.format(bits.replace('0b', '').rjust(8, '0')))
13
+ attempts += 1
14
+ if int(answer) == rand_num:
15
+ print('*** Correct! ***')
16
+ correct = True
17
+ else:
18
+ if attempts > 3:
19
+ print('The answer is: {}'.format(rand_num))
20
21
22
+ print('Try again.')
23
24
25
+def main():
26
+ bit_test()
27
28
+if __name__ == '__main__':
29
+ main()
0 commit comments