CS 115 Lab 1, Part A: Edit a text-based Python program using IDLE

[Back to Lab 1 instructions]


Summary

In this part of the lab, you will use IDLE to write and run a Python program. The screenshots on this page were taken on a Mac, but IDLE should work similarly on Windows.

Instructions

  1. If you haven't done the pre-lab assignment yet, do it first!! You will need to open up the pre-lab instructions in one tab and the Moodle "quiz" in another.
  2. Open IDLE.
  3. In IDLE, go to the File menu and select New File or New Window:
    Making a new IDLE window
  4. In the new IDLE window (not the Python Shell window), type in (or copy-paste) the following program exactly as written:
    """
    Lab 1: This program prompts for your name and then greets you by name.
    Author: ____________
    """
    
    
    def main():
        name = input('What is your name? ')
        print('Hi there,', name)
    
    
    main()
    
  5. Modify the docstring at the top of the program to add yourself as the author of the program.
  6. Go to the File menu, then select Save As. Save your program as lab01.py in the current folder (which should be C:\Python34 in Windows and the Documents folder in Mac OS):
    Saving your Python program
  7. Go to the Run menu, then select Run Module:
    Running your Python program

    After you select "Run Module," your program will run in the other window (the "Python Shell" window):
    Running your Python program
  8. When you are prompted, type your name and hit the return key.
  9. Keep the docstring at the top, but modify the rest of your program so that it looks like this:
    def main():
        name = input('What is your name? ')
        print('Hi there, ', name, '.', sep="")
    
    
    main()
    
  10. Run your program again. Notice how the output changed, and be sure you understand why.
  11. Answer Question 1 in the Lab 1 writeup. Be sure to check your answers.
  12. Back in your source code window, modify the program so that it asks you for your favorite movie and then tells you that your taste is terrible. Here is an example of what your program should do. In this example, the user's input is underlined and italicized, and the rest of the text should be printed by your program:
    What is your favorite movie? Transformers
    Ugh, Transformers is a terrible movie.
  13. Here is another example. In this example, the user's input is Mission Impossible.
    What is your favorite movie? Mission Impossible
    Ugh, Mission Impossible is a terrible movie.
  14. Change the first line of the docstring so that it accurately describes what the program does now.
  15. Continue to Part B.