Computers and Programs

In this topic, we explore the concept of computer programs, specifically Python programs.

You will learn how to use the IDLE Python development application. A short program will downloaded, modified slightly.

Tutorial

Read up on this Python and IDLE tutorial The Python Interpreter and IDLE, and The IDLE Editor and Execution.

Your Assignment

  1. Open the IDLE application. Open a new editor window using File->New Window.

  2. Type in the following program:

    # File: chaos.py
    # A simple program illustrating chaotic behavior.
    
    def main():
        print("This program illustrates a chaotic function")
        x = eval(input("Enter a number between 0 and 1: "))
        for i in range(10):
            x = 3.9 * x * (1 - x)
            print(x)
    
    main()
    
  3. Save the program using File->Save under the name lab-computer-programs.py.

  4. Run the program by first selecting Run->Module, and then switching to the Python shell window, and typing main().

  5. Modify your lab_computer_programs.py program 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 = eval(input("How many numbers should I print? "))
    

    Then you will need to change the loop to use n instead of a specific number.

Submission Requirements

Your file is required to be named lab_computer_programs.py.

Please read and follow the Submission Requirements to avoid point deductions specified below.

Grading

The following is the grading rubric for this lab to be used by the course graders. The lab is worth 100 points.

Note: There may be additional criteria for grading, this is just a summary of the major rubric items.

Grading Rubric
Type Description Point Loss (Max)
  [General]  
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
  [Lab Specific]  
Prompting Doesn’t ask the user for the number of iterations -15
Iterations Doesn’t use the correct number of iterations in the for loop based on user input -15