Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9e3412

Browse files
committed
Bit test. Read them bits!
1 parentfe1f4cc commitd9e3412

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎experiments/bit_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
importrandom
2+
3+
4+
defbit_test():
5+
keep_going=True
6+
whilekeep_going:
7+
rand_num=random.randint(0,0xFF)
8+
bits=bin(rand_num)
9+
correct=False
10+
attempts=1
11+
whilenotcorrect:
12+
answer=input('What is {} in decimal? '.format(bits.replace('0b','').rjust(8,'0')))
13+
attempts+=1
14+
ifint(answer)==rand_num:
15+
print('*** Correct! ***')
16+
correct=True
17+
else:
18+
ifattempts>3:
19+
print('The answer is: {}'.format(rand_num))
20+
correct=True
21+
else:
22+
print('Try again.')
23+
24+
25+
defmain():
26+
bit_test()
27+
28+
if__name__=='__main__':
29+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp