-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturn_binary.py
More file actions
54 lines (52 loc) · 823 Bytes
/
turn_binary.py
File metadata and controls
54 lines (52 loc) · 823 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
a = ''
a =input('please input the number: ')
b = ''
zero=[' 000',
' 0 0',
'0 0',
'0 0',
'0 0',
' 0 0',
' 000']
one=[' 1 ',
'111 ',
' 1 ',
' 1 ',
' 1 ',
' 1 ',
'11111']
def pr_zero(a):
for i in range(7):
print zero[i]
def pr_one(a):
for i in range(7):
print one[i]
def pr(a):
if a == 0:
pr_zero(a)
elif a == 1:
pr_one(a)
while a > 0:
if a % 2 == 1:
b = b+'1'
a = a / 2
elif a % 2 == 0:
b = b+'0'
a = a / 2
elif a == 1:
b = b+'1'
def reverse(string):
begin = 0
end = len(string) - 1
strlist = [i for i in string]
while(begin < end):
a = strlist[begin]
strlist[begin] = strlist[end]
strlist[end] = a
begin += 1
end -= 1
return "".join(strlist)
b = reverse(b)
for i in b:
pr(int(i))
print