def print_multples(n):
i = 1
while i <= 6:
print n * i, '\t',
i += 1
def print_mult_table(high):
i = 1
while i <= high:
print_multiples(i)
i += 1
So for example, if we plug in print_mult_table(7) we get the following table:
1 2 3 4 5 6 7
2 4 6 8 10 12 14
3 9 12 15 18 21
4 8 12 16 20 24 28
5 10 15 20 25 30 35
6 8 12 18 24 30 36 42
7 14 21 28 35 42 49
(sorry this time i didn't try to equal up the sides of the table)
This program makes it where the table will have a downwards slope as the number rises. This table also takes away the numbers 2-7 from the top row, then each row it adds another number. Here is the table so you understand what I mean:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
I then started to work on Newton's method which the program was:
def sqrt(n): approx = n/2.0 better = (approx + n/approx)/2.0 while better != approx: approx = better better = (approx + n/approx)/2.0 return approx
I then plugged in sqrt(25) and got an out-put of 5.0:
>>> sqrt(25) 5.0
Your code is getting involved enough that you will need to move code listings out of the blog, and just link to them.
ReplyDeleteAgain, let's talk on Monday.