2 thoughts on “Udacity – Intro to Computer Science – Python – 10 Row Abacus”

  1. i = 9
    while i >= 0:
    print “|00000*****|”[:11-(value / 10i)] + ” ” + “|00000*****|”[11-(value / 10i):]
    value, i = value – 10i * (value / 10i), i – 1

  2. Found a shorter way to do it and earn the bonus points

    def print_abacus(value):
    i=9
    while i>=0:
    power=int(str(value/(10**i))[-1])
    if power<6:
    print ‘|’+5‘0’ +(5-power)‘+3‘ ‘+power‘+’|’
    else:
    print ‘|’+(10-power)‘0’+3‘ ‘+(power-5)‘0’+ 5‘*’+’|’
    i=i-1

Comments are closed.