Computers and Programs

In this topic, we explore the concept of computer programs, specifically Python programs. We’ll learn how to use the IDLE Python development application, both through the use of the interpreter (the >>> prompt!) and also the text editor functionality, where we will download a short program, modify it slightly and then execute it to register that you’ve completed this task.

Part 2: 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.

Part 3: Submission

In this course, I will try to instill best practices with regard to writing code. There are a few standards to adhere to when submitting your lab. Please read, and follow them carefully.

Submission Filename

Submission requires that you hand in a file called lab_computer_programs.py.

Documentation String (“docstring”)

Read up on docstrings on the Program Documentation String page. Docstrings consist of three quotes ("""), a summary line, followed by a blank line, followed by a more elaborate description, and ending with three quotes. This will be required to be the very first thing in your Python program file.

"""CSC 161 Lab: Computers and Programs

Fox Mulder
Lab Section TR 2:00-3:15pm
Fall 2015
"""

Python Code Style

This lab will introduce the idea of Pythonic Coding Style, a set of coding guidelines to make your Python code more readable and maintainable. You will need to run your Python program file lab_computer_programs.py through the online PEP 8 style checker found in CSC 161 Style.

Other Details

Otherwise, the Blackboard post for this lab assignment will contain the details regarding the due date and other details regarding class administration for this assignment.

Part 4: Grading

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

Here’s a brief grading rubric. If the program…

  • has a bad/missing docstring header comment (i.e. no name, lab section, etc), -10 points
  • has syntax errors, -20 points
  • doesn’t ask the user for the number of iterations, -20 points
  • doesn’t use the correct number of iterations in the for loop based on user input, -10 points
  • doesn’t have a main() function, -10 points

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