Skip to content

wingclover/Udacity-abacus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Udacity-abacus

optional homework at Udacity. Print out abacus

First time using github. Not sure how everything works. Here is a backup of my homework: ##my best solution so far:

def print_abacus(value): # ### Add you code here # string_number = "0"*(10-len(str(value))) + str(value) original = "|00000*****|" for number in string_number: print original[:(11-int(number))] + " " + original[(11-int(number)):]

#########################################################################

10-row School abacus

by

Michael H

#########################################################################

Description partially extracted from from wikipedia

Around the world, abaci have been used in pre-schools and elementary

In Western countries, a bead frame similar to the Russian abacus but

with straight wires and a vertical frame has been common (see image).

Helps schools as an aid in teaching the numeral system and arithmetic

|00000***** | row factor 1000000000

|00000***** | row factor 100000000

|00000***** | row factor 10000000

|00000***** | row factor 1000000

|00000***** | row factor 100000

|00000***** | row factor 10000

|00000***** | row factor 1000

|00000**** *| row factor 100 * 1

|00000*** **| row factor 10 * 2

|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.

######################################################################

TASK:

Define a procedure print_abacus(integer) that takes a positive integer

and prints a visual representation (image) of an abacus setup for a

given positive integer value.

Ranking

1 STAR: solved the problem!

2 STARS: 6 < lines <= 9

3 STARS: 3 < lines <= 6

4 STARS: 0 < lines <= 3

def print_abacus(value): # ### Add you code here #

   original = "|00000*****|"
   length = len(str(value))
   for i in range(10-length):
        print original[:-1] + "   " + original[-1:]
        
   for number in str(value):
        print original[:(11-int(number))] + "   " + original[(11-int(number)):]

TEST CASES

print "Abacus showing 0:" print_abacus(0) #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | print "Abacus showing 12345678:" print_abacus(12345678) #>>>|00000***** | #>>>|00000***** | #>>>|00000**** | #>>>|00000** | #>>>|00000 | #>>>|00000 | #>>>|00000 | #>>>|0000 0| #>>>|000 00| #>>>|00 000****| print "Abacus showing 1337:" print_abacus(1337) #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000***** | #>>>|00000**** | #>>>|00000* | #>>>|00000 | #>>>|000 00*|

About

optional homework at Udacity. Print out abacus

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published