Homework #1

Due Date: April 6, 2009 Points: 100

Written Exercises

  1. (4 points each) Please define the following terms in one or two sentences:
    1. Computer program
    2. Intractable
    3. Fetch-execute cycle
    4. Programming language syntax
    5. Interpreter
  2. (2 points each) Start up an interactive Python session and try typing in each of the following commands. Write down the results you see.
    1. print "Where ever you go"
    2. print "What" "ever" "you" "do"
    3. print what ever you do
    4. print 3
    5. print 3 + 4
    6. print 3 + 2 * 2
    7. print (3 + 2) * 2
    8. print 3 + (2 * 2)
    9. print 3 + 2
    10. print "3" + "2"
    11. print "3 + 2 = ", 3 + 2
    12. print 3 * 2
    13. print 3 ** 2
    14. print 3 / 2
    15. print 3.0 / 2.0

Programming Exercises

  1. (15 points) Enter and run the Chaos program, with the following change: this line:

    x = 3.9 * x * (1 - x)

    to:

    x = -0.8 * x * x + 1

    Try it out with at least 3 values. Turn in your program in the file “chaos3.py”.
  2. (15 points) Modify the Chaos program you used in question 3 to print out 20 values instead of 10. Turn in your program in the file “chaos4.py”.
  3. (20 points) Modify the Chaos program you used in question 3 so that the number of values to print is determined by the user. You will have to add a line near the top of the program to get another value from the user:

    n = input("How many numbers should I print? ")

    Then you will need to change the loop to use n instead of a specific number. Turn in your program in the file “chaos5.py”.

Extra Credit (Written)

  1. (5 points) Have the modified Chaos program print many values. What do you notice about the values it prints? Are they completely random, or do they appear to approach one or more values?