From bdf751293ec62f361985430ec748726883b4831a Mon Sep 17 00:00:00 2001 From: Dinko Galetic Date: Fri, 11 Jun 2010 08:54:12 +0000 Subject: Made numbers right aligned. --- 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') -- cgit v0.9.1