Last active
November 23, 2016 15:24
-
-
Save AmaxJ/fab8a8a279ea644efec4 to your computer and use it in GitHub Desktop.
Abacus Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Abacus script | |
#Enter a value and have it printed out in abacus form | |
from numFinder import * | |
from rep import * | |
# checks if value is between 1 and 1 billion. | |
def valid_Num(num): | |
if num <= 1000000000 and num >= 0: | |
return True | |
else: | |
return False | |
def abacus(num): | |
if valid_Num(num) == True: | |
rep(bils(num)) | |
rep(hund_mils(num)) | |
rep(ten_mils(num)) | |
rep(mils(num)) | |
rep(hund_thous(num)) | |
rep(ten_thous(num)) | |
rep(thous(num)) | |
rep(hunds(num)) | |
rep(tens(num)) | |
rep(ones(num)) | |
else: | |
print 'Please enter a value between 1 - 1000000000' | |
x = int(raw_input('Enter a number to see it on the abacus: ')) | |
abacus(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#determines how many digits long the value entered into abacus is | |
#and returns the number for each place | |
def ones(num): | |
if len(str(num)) >= 1: | |
ones = str(num)[-1] | |
return int(ones) | |
else: | |
return False | |
def tens(num): | |
if len(str(num)) >= 2: | |
tens = str(num)[-2] | |
return int(tens) | |
else: | |
return False | |
def hunds(num): | |
if len(str(num)) >= 3: | |
hunds = str(num)[-3] | |
return int(hunds) | |
else: | |
return False | |
def thous(num): | |
if len(str(num)) >= 4: | |
thous = str(num)[-4] | |
return int(thous) | |
else: | |
return False | |
def ten_thous(num): | |
if len(str(num)) >= 5: | |
ten_thous = str(num)[-5] | |
return int(ten_thous) | |
else: | |
return False | |
def hund_thous(num): | |
if len(str(num)) >= 6: | |
hund_thous = str(num)[-6] | |
return int(hund_thous) | |
else: | |
return False | |
def mils(num): | |
if len(str(num)) >= 7: | |
mils = str(num)[-7] | |
return int(mils) | |
else: | |
return False | |
def ten_mils(num): | |
if len(str(num)) >= 8: | |
ten_mils = str(num)[-8] | |
return int(ten_mils) | |
else: | |
return False | |
def hund_mils(num): | |
if len(str(num)) >= 9: | |
hund_mils = str(num)[-9] | |
return int(hund_mils) | |
else: | |
return False | |
def bils(num): | |
if len(str(num)) == 10: | |
bils = str(num)[0] | |
return int(bils) | |
else: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#prints the visual representation of the number in | |
#abacus form. | |
ab_visual = ['|00000***** |', '|00000**** *|', '|00000*** **|', | |
'|00000** ***|', '|00000* ****|', '|00000 *****|', | |
'|0000 0*****|', '|000 00*****|', '|00 000*****|', | |
'|0 0000*****|', '| 00000*****|'] | |
def rep(num): | |
if num == False: | |
print '|00000***** |' | |
else: | |
print ab_visual[num] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment