Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinko Galetic <dgaletic@everflame.(none)>2010-06-11 08:54:12 (GMT)
committer Dinko Galetic <dgaletic@everflame.(none)>2010-06-11 08:54:12 (GMT)
commitbdf751293ec62f361985430ec748726883b4831a (patch)
treef8c59ce866793a3879a1ce68a20b6874cc2dbff0
parent88cc999c9b273c2017d96c7c9aa043495b93b2e7 (diff)
Made numbers right aligned.
-rw-r--r--data/GSOC examples/multiplication table14
1 files changed, 7 insertions, 7 deletions
diff --git a/data/GSOC examples/multiplication table b/data/GSOC examples/multiplication table
index fd3c988..8478c6e 100644
--- a/data/GSOC examples/multiplication table
+++ b/data/GSOC examples/multiplication table
@@ -35,29 +35,29 @@ column = range(1, y+1)
output = ""
# the first printed line, for decoration:
# add the beginning of it
-output += "|-------|--"
+output += "|--------|--"
# for each number in a row, add eight dashes and mark the end of line with \n
# \n is called a 'newline' and it makes your console start writing a new line.
output += len(row) * "--------" +"\n"
-# What the second line starts with. \t marks one tab.
-output += "|\t|\t"
+# What the second line starts with.
+output += "|" + 8 * " " + "|"
# Now, we would like to print the first row of numbers, which
# represent the factors we'll multiply. Add each number from "row"
# to the output string. str(number) turns a number to characters
# (like number 42 to characters '4' and '2')
for number in row:
- output += str(number) + "\t"
+ output += "{0:>8}".format(number)
# add another decorative line
-output += "\n" + "|-------|--" + len(row) * "--------" + "\n"
+output += "\n" + "|--------|--" + len(row) * "--------" + "\n"
# for each number in the first column, multiply it with each number in the
# first row. One by one, add the results to "output" and print it.
for factor1 in column:
- output += "| " + str(factor1) + "\t|\t"
+ output += "|{0:>6} |".format(factor1)
for factor2 in row:
- output += str(factor1*factor2) + "\t"
+ output += "{0:>8}".format(factor1*factor2)
# clear the screen from what was last printed (old output) so
# we can print the new output (with one result added)
os.system('clear')