1. How to Program, Part I
  2. How to Program, Part II
  3. How to Program, Part III
  4. How to Program, Part IV
  5. How to Program, Part V
  6. exercises
  7. pyMPI tutorial
  8. Calculating PI, Part I
  9. Calculating PI, Part II
  10. Calculating PI, Part III
  11. Poogle - Web Search
  12. Mandelbrot Sets
  13. Mandelbrot, The Code
  14. Mandelbrot, The Images
  15. Conway's Life, Part I
  16. Life Code Listing
  17. Conway's Life, Part II
  18. MPI Life Code Listing

exercises

  1. Write a program to take the sum of all integers from 2 to 17 excluding 13.
  2. The Fibonacci sequence is a sequence of numbers that proceeds as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, etc. Each number is the sum of the previous two. We can write a function to compute a number in this sequence using Python:
    file: fib.py
    1 def fib(n):
    2     if n == 0:
    3         return 0
    4     elif n == 1:
    5         return 1
    6     return fib(n-1)+fib(n-2)
    7 
    8 print fib(7)
    > python fib.py
    13
    When a function calls itself (the way fib() does) it is called recursion. Use recursion to write a program to compute a factorial (4! = 4*3! = 4*3*2*1, and 1!=1)
  3. Write a program to make a copy of an array with the even integers removed. You can test for whether a number is even by using the % operator.
    file: remain.py
    1 import random
    2 
    3 # create a list of 10 random integers from 1 to 100
    4 # define a function that returns a new array that is
    5 # the same as your randomly generated one, except that
    6 # the even numbers are removed.
    7 a = []
    8 for i in range(10):
    9     a.append(random.randint(1,100))
    10 print a
    11 
    12 # Here's how you calculate remainders:
    13 print "remainder of 15 / 2 =",15 % 2
    14 print "remainder of 39 / 3 =",39 % 3
    > python remain.py
    [45, 60, 45, 100, 18, 10, 82, 83, 35, 63]
    remainder of 15 / 2 = 1
    remainder of 39 / 3 = 0
  4. Write a program to convert a decimal number to an array of digits. In other words, make a function that converts 1298 to [1,2,9,8].
  5. Write a program to convert an array of digits to a number. In other words, one that converts [3,9,5,2] to 3952.
  6. Write a program to convert an array of decimal digits to octal digits.
  7. Write a program to convert an array of octal digits to decimal digits.
  8. Write a program to compute the answer to the quadratic formula. In other words, create a function that takes three values: a,b, and c, and returns the two solutions of a*x**2+b*x+c==0.
  9. Write a program to determine whether a number is a perfect square. The program should print "true" if it is a perfect square and "false" otherwise.
  10. Using the fact that string is an array of characters, write a find() program that works like string's find method.
  11. Write a program to sort an array. First, create a random array as follows:
    file: sort.py
    1 import random
    2 
    3 a = []
    4 for i in range(10):
    5     a.append(random.randint(1,100))
    6 print a
    7 
    8 # put code here that sorts array a
    > python sort.py
    [40, 64, 13, 24, 57, 68, 83, 11, 1, 31]
Further research: Simple Python Programs.