-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbacus.py
More file actions
54 lines (48 loc) · 1.26 KB
/
Abacus.py
File metadata and controls
54 lines (48 loc) · 1.26 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def print_abacus(value):
#x=9
#while(x>=0):
#cnt=(int)(value/pow(10,x))
#print ("|"+("0"*(5-(cnt%5)))+(" "*(int)(cnt/5))+("0"*(cnt%5))+(("*")*(5-(cnt%5)))+((" ")*(1-(int)(cnt/5)))+(("*")*((cnt%5)))+"|")
#value-=cnt*pow(10,x)
#x-=1
for x in range(0,10):
cnt=(int)(value/pow(10,9-x))
print ("|"+("0"*(5-(cnt%5)))+(" "*(int)(cnt/5))+("0"*(cnt%5))+(("*")*(5-(cnt%5)))+((" ")*(1-(int)(cnt/5)))+(("*")*((cnt%5)))+"|")
value-=cnt*pow(10,9-x)
### TEST CASES
print ("Abacus showing 0:")
print_abacus(0)
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
print ("Abacus showing 12345678:")
print_abacus(12345678)
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000**** *|
#>>>|00000*** **|
#>>>|00000** ***|
#>>>|00000* ****|
#>>>|00000 *****|
#>>>|0000 0*****|
#>>>|000 00*****|
#>>>|00 000*****|
print ("Abacus showing 1337:")
print_abacus(1337)
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000***** |
#>>>|00000**** *|
#>>>|00000** ***|
#>>>|00000** ***|
#>>>|000 00*****|