CSE 161 Assignment #1: Using IDLE


This is an algorithm for learning to use the Python programming environment IDLE. Before starting, you will need to buy a USB Flash drive that is 1 GB or larger in size. You can buy a 2 GB flash drive from the UR Computer Store or any drug or office supply store for about $10. Check off each step you perform below and sign it. Turn this sheet in in class on Wed 9/9.

  1. ____ Open the IDLE application. Open a new editor window using File->New Window. Define a function named "main" that prints "Hello, World!". Save the program using File->Save under the name MyFirstProgram.py. Run the program by first selecting Run->Module, and then switching to the Python shell window, and typing main().
  2. ____ Switch to the computer desktop, and find your file MyFirstProgram.py. Insert your USB drive in the computer and copy the file to it. Safely remove the USB drive by first selecting the drive's icon the desktop, right-clicking and selecting Eject, and finally unplugging the drive. Open a web browser and go to your email account. Send an email message to yourself with the file MyFirstProgram.py as an attachment.
  3. ____ Move to a different computer. Plug in your USB drive and copy MyFirstProgram.py to your home folder. Change the name of the file to MySecondProgram.py. Open a web browser, go to your email, find the message that you just sent yourself, and download the file MyFirstProgram.py to your home directory.
  4. ____ Start up IDLE. Open the file MySecondProgram.py using File->Open. Change the program so that it prints "Goodbye, Cruel World!". Run it, just as you did in step (1).
  5. ____ Open the file MyFirstProgram.py in a new window. Run it, just as you did in step (1).
  6. ____ Every time you select Run->Module from a editor window the Python interpreter is restarted, erasing whatever programs were entered before. Now we'll see how to keep two different files (also called "modules") loaded into Python at the same time. Go to the Python shell window. Restart it using Shell->Restart Shell. In the shell window, type the lines:

    import MyFirstProgram

    import MySecondProgam

    If you get an error message, then IDLE is having difficulty finding your files. Ask the lab TA for help. (He or she may need to check the value of the variable sys.path, which lists the folders that Python will search for files.) Now check that you can run the two different functions by typing


    or by typing


    Why do you think you need to type e.g. MyFirstProgram.main() rather than just main() as before?

  7. ____ One program file (or module) can cause another module to be loaded. Open MyFirstProgram.py and add the line
    import MySecondProgram
    at the top of the file. Now, in the body of your program Main(),after the command to pring "Hello, World!", add the line
  8. MySecondProgram.main()

Save the file. Now click Run->Module. Finally, see what happens when you type MyFirstProgram.main() in the Python shell window.

I confirm that I completed this assigment:
First name: _______________________
Last name: _______________________
Signature: ________________________