def abaci(i): #converts a number 0-9 (in string form) to it's respective abaci value if i == "0": return "|00000***** |" if i == "1": return "|00000**** *|" if i == "2": return "|00000*** **|" if i == "3": return "|00000** ***|" if i == "4": return "|00000* ****|" if i == "5": return "|00000 *****|" if i == "6": return "|0000 0*****|" if i == "7": return "|000 00*****|" if i == "8": return "|00 000*****|" if i == "9": return "|0 0000*****|" def tenrow(i): #Converts an integer to a string and adds 0's to the start of the string, making it 10 digits. ie. 1 becomes '0000000001' #TODO: Throw error if user enters string longer than 10 digits zeros = 10 - len(str(i)) return "0" * zeros + str(i) def print_abacus(int): #Prints out the abacus line by line for x in range(10): print abaci(tenrow(int)[x]) #print tenrow(1) #print abaci(str(9)) print "Abacus 0" print_abacus (0) print "Abacus 12345678" print_abacus (12345678) print "Abacus 1337" print_abacus (1337)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question