Using an abacus to represent numbers, Python implements

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.