MF 703
Fall 2017

Lab 1

Getting Started With Python and IDLE

Preliminaries

This lab consists of some exercises to help you become comfortable with the the basics of Python and the IDLE IDE.

Task 1: install the necessary software

In your work for this course, you will need to have access to the following programming tools:

The steps needed to obtain and install these tools depend on the operating system that you’re using. Select the appropriate link below:

Task 2: explore IDLE

First, start the IDLE program. If you are using your own computer, you should have installed some version of Python 3 (see task 1). If you need help locating the IDLE program on your own computer, ask one of the teaching staff members to help you.

Let’s review the basics of using IDLE. The easiest way to do so is to download a Python file, open it in IDLE, and then run it in IDLE.

Note

When working on a machine in the lab, you should save all of your work on the Z: drive. This is a special directory maintained by the computer science department which is accessible from any computer to which you are logged on using your CS account (either in the teaching lab or in the undergraduate lab). If you do not save your work to the Z: drive, you will not be able to access your work again after you log out!

To make it easier to manage the browser (the guide to the lab), the text editor (where you are developing a program), and the Python Shell (where Python runs and displays results) on your computer, we recommend resizing and rearranging the windows in the following way:

IDLE

This allows you to make the best use of all three windows simultaneously.

Task 3: modify IDLE’s settings

To facilitate your use of IDLE, we recommend that you take the following steps to change IDLE’s settings:

  1. Click the Options menu, then click Configure IDLE. (On OS X, you would click the IDLE menu and then Preferences.)

  2. In the resulting window, use the drop-down box to change the font size to at least 12 points.

  3. In the same window, select the Keys tab.

  4. In the section of the Keys tab called Custom Key Bindings, scroll down to find the line for history-next.

  5. Click on the line for history-next and then click the button labeled Get New Keys for Selection. In the resulting window, scroll down to find and select Down Arrow. Then click OK.

  6. When prompted, enter a name for your new Custom Key Set. You can just use your first name. Click OK.

  7. Click on the line for history-previous and then click the button labeled Get New Keys for Selection. In the resulting window, scroll down to find and select Up Arrow. Then click OK.

Task 3.1: Changing IDLE’s font size

On some computers, IDLE’s default font size is too small. In these cases, the _ character (the underscore) may be too small or invisible. Since we will use the _ character very frequently when writing Python code, you should change IDLE’s font size to at least 12 points.

On OS X:

On Windows:

Task 4: understand and debug Python code

Create a new file in IDLE and name it lab1task4.txt. Put all answers that you write for this task in this file.

Let’s take another look at the program from Task 2.

  1. What types of statements are included in this program?

  2. In what order are the statements executed?

  3. Explain in detail what happens when the following two statements are executed:

    course = course + 1
    print('maybe you will take CS', course, 'next semester')
    
  4. Consider the following two lines of the program:

    weeks = days // 7
    print('that is approximately', weeks, 'weeks')
    
    1. What is the difference between weeks and 'weeks'?

    2. Why does the program print 5 weeks instead of 6 or 5.7142857...?

    3. How could we make the program print a more precise result for the number of weeks?

  5. Copy and paste the following lines into the program, after all of the existing lines:

    print()
    print('Go Terriers!")
    print('pi is approximately' (22 / 7)
    
  6. Save the changes to the program using Ctrl-S. Then try to run it using F5. What happens?

  7. The new lines include several bugs. See if you can find and fix them. Feel free to ask the TF or CA if you need help.