1 #########################################################################2 #10-row School Abacus3 # by4 #Michael H5 #########################################################################6 #Description partially extracted from Wikipedia7 #8 #Around The world, Abaci has been used in pre-schools and elementary9 #Ten #in Western countries, a bead frame similar to the Russian abacus but One #With straight wires and a vertical frame have been common (see image). A #helps schools as an aid in teaching the numeral system and arithmetic - # - #|00000***** | Row Factor 1000000000 the #|00000***** | Row Factor 100000000 - #|00000***** | Row Factor 10000000 - #|00000***** | Row Factor 1000000 - #|00000***** | Row factor 100000 + #|00000***** | Row Factor 10000 - #|00000***** | Row Factor + #|00000**** *| Row Factor * 1 A #|00000*** **| Row Factor * 2 at #|00000** ***| Row Factor 1 * 3 - # ----------- - #Sum 123 - # - #Each row represents a different row factor, starting with X1 at the - #bottom, ascending up to x1000000000 at the top row. in ###################################################################### - to #TASK: + #Define a procedure print_abacus (integer) that takes a positive integer - #and prints a visual representation (image) of an abacus setup for a the #given positive integer value. * # $ #RankingPanax Notoginseng #1 star:solved the problem! - #2 Stars:6 < lines <= 9 the #3 Stars:3 < lines <= 6 + #4 stars:0 < lines <= 3 A the defPrint_abacus (value): +Row_number = 1 - whileRow_number <= 10: $Number = value//(10** (10-row_number)) $ ifNumber = =0: - Print '|'+'0'+'*'+' '+'|' - elifNumber > 0 andNumber < 5: the Print '|'+'0'+'*'* (5-number) +' '+'*'*number +'|' - Else:Wuyi Print '|'+'0'* (10-number) +' '+'0'* (NUMBER-5) +'*'+'|' theValue-= number* (10** (10-row_number)) -Row_number + = 1 Wu - About $ - - ## TEST CASES - Print "Abacus showing 0:" A print_abacus (0) + #>>>|00000***** | the #>>>|00000***** | - #>>>|00000***** | $ #>>>|00000***** | the #>>>|00000***** | the #>>>|00000***** | the #>>>|00000***** | the #>>>|00000***** | - #>>>|00000***** | in #>>>|00000***** | the Print "Abacus showing 12345678:" thePrint_abacus (12345678) About #>>>|00000***** | the #>>>|00000***** | the #>>>|00000**** *| the #>>>|00000*** **| + #>>>|00000** ***| - #>>>|00000* ****| the #>>>|00000 *****|Bayi #>>>|0000 0*****| the #>>>|000 00*****| the #>>>|00 000*****| - Print "Abacus showing 1337:" -Print_abacus (1337) the #>>>|00000***** | the #>>>|00000***** | the #>>>|00000***** | the #>>>|00000***** | - #>>>|00000***** | the #>>>|00000***** | the #>>>|00000**** *| the #>>>|00000** ***|94 #>>>|00000** ***| the #>>>|000 00*****|
Results