sep 23
1. From homework : formatting multiple values; formatting strings.
# A table of integers and square roots.
from math import sqrt
print " %8s %8s" % ('n', 'sqrt(n)')
print " %8s %8s" % ('-'*8, '-'*8)
for n in range(1, 11):
print " %8i %8.4f" % (n, sqrt(n))
which does this :
$ python sqrts.py
n sqrt(n)
-------- --------
1 1.0000
2 1.4142
3 1.7321
4 2.0000
5 2.2361
6 2.4495
7 2.6458
8 2.8284
9 3.0000
10 3.1623
2. Also from homework : cipher wrap, i.e. 'y' + 10 using mod arithmetic.
New homework for chapter 5 (object oriented graphics) is posted.
Now: practice with the graphics package described last time.
Group exercise in class : write a program that plots of graph of y = sin(x) .