Lab: Greetings!

Running a python program, input, output and variables

Part I. Running Python code

First things first, make sure your Python environment is working and that you can write and run a program.

Step 1: Launch IDLE from the Python 3 (not Python 2!) install on your computer

This will bring up the interactive command line interface, where you can type lines of code and Python will immediately interpret them:

Step 2: Make sure it works

Run a print command, just like in the example above, to print a string that describes the beauty of a cherry blossom under the summer moon. Or, you know, whatever.

Step 3: Explore

Grab your neighbor and do this part together on one computer!

For each of the following lines of code, agree (out loud!) about what you think will happen. Then run it and see what Python does. If it's not what you expected, discuss why. Don't skip predicting the output!

Make a list together (on paper) of things about Python that you figured out (or confirmed) from those experiments. Rules about syntax (what you can say) and semantics (what it means to the interpreter). Put your names on it and hand it in.

  • print("Hi there person", "I think you are grand")
  • print(4)
  • print(4, 5, "six six six")
  • printzzz("Hi there person")
  • print(Hi there person)
  • print Hi there person
  • print(name)
  • name = "Bob"
  • print(name)

Part II. A first program

For this lab, you are going to write a Python program that interacts with a user at the command line. Instead of exectuing code statements at the interactive prompt, you are going to put your program in a file and run it all at once.

  1. In IDLE, click on the File menu and select "New File" to open a new file in the default editor
  2. In that file, type a print statment, just like you did in part I.
  3. Click the File menu in the editor and select "Save" to save the file somewhere.
  4. Name it lab01.py and remember where you saved it! That's the file you'll turn in.
  5. To execute the program in that file, click the Run menu in the editor and select "Run Module". The print output will show up in the interactive prompt window. You can also press the F5 key as a shortcut.

The Greeting Lab

Write a sequence of Python statements (lines of code) in your file to implement this interaction with the user. (The program must stop to wait for the user to type their name and age).

Hello! What is your name? emmett
And how old are you? 42
42 is a great age, emmett.

Test your code with multiple inputs and make sure it does what you think it should all the time!