Friday, February 25, 2011

Feb 25

So starting with tables, they seem easy pretty easy to understand, well at least the one I've tired. The program is:
x = 1
while x < 13:
        print x, '\t\' , 2**x
       x += 1
This program is basically having calling x to count up to 1-12 on one side of the table('\t\' is keyed together with table). Then on the right side the number starts from 2 then doubles, then doubles, then a that number doubles and so on and so forth.
Then working with the two dimensional table program:

i = 1
>>> while i <= 6:
...     print 2 * i, '  ',
...     i += 1
... print
You get an outcome of the number just counting up by 2s starting with 2 and counting on. Also with this program it tells the number to be spaced 3 times after it is outputted on the table, for example:
2   4   6    8   10   12   14   16   18   20.... and so on.
def print_multiples(n):
...     i = 1
...     while i <= 6:
...             print n * i, '\t\', 
...             i += 1
...     print
When you plug 2 into this program you get:
3   6   9  12  15  18... and so on.
But then when you change the 2 to 4 you get an outcome of:
4   8   12   16   20....and so on. 
The next program combines a few tables to produce a big table:def print_multiples(n):
i = 1
while i <= 6:
print n * i, '\t', 
i += 1
i = 1
while i <= 6:
print_multiples(i)
i += 1
With an outcome of: (sorry took some numbers out so that table look a little equal, side wise) 
1   2   3   4   5   6
2   4   6   8   10  12
3   6   9   12  15  18
4   8   12  16   20
5   10   15   20   25
6   12   18   24   30


1 comment:

  1. Nice work, as usual. Please don't hesitate to ask questions if you have any (it makes me feel useful ;-), though it is apparent from your posts that you are understanding what you are reading in the book.

    ReplyDelete