-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabacus.py
More file actions
21 lines (20 loc) · 849 Bytes
/
Copy pathabacus.py
File metadata and controls
21 lines (20 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Define a procedure my_abacus(integer) that takes a positive integer and prints a visual representation of an abacus.
def my_abacus(value):
x= str(value)
i = (10 - len(str(value)))
while i > 0:
x = '0' + x # Appending 0 in front of the str to make it a 10 digit value i.e. 1234 becomes 0000001234
i = i - 1
while i < 10:
out = '|'
j = 0
while j < 10:
if j < 5:
out = out + '0'
else:
out = out + '*'
j = j + 1
if j == (10 - int(x[i])):
out = out + ' ' #When count value equal to 10- integer value, print seperation. (10 - Integer value) because you print from the left.
i = i + 1
print out + '|' #print 1 line. repeat 10 times for each value in the 10 digit abacus