Home CPSC 110

Hello World

Objective

To get Python installed and configured on your computer, and gain experience writing, executing and turning in Python code.

Installing Python

  1. Go to the Python download page.
  2. Click the most recent Python 3 release link (currently 3.7.2).
  3. Scroll down to the "Files" section.
  4. If using a Windows computer, choose the "Windows x86-64 executable installer".
  5. If using a Mac computer, choose the "macOS 64-bit installer".
  6. After the download finishes, run the installer that you downloaded.
  7. Follow the on screen instructions to complete the installation.

Running IDLE

The installation actually installs not only Python, but an editor program called "IDLE". You should be able to find IDLE under your applications menu.

When you execute it, you should see a window like this:


The IDLE shell


Running Code Interactively

This window is called a "shell". It is waiting for you to enter commands to be executed. When you enter commands, it runs them right away and then waits for you to enter another command.

We can type our print command in here, to ask the shell to print something to the screen for us. We can also use it as a sort of calculator:


Entering commands into IDLE

This is one way to run Python code: interactively in the shell.


Saving a Program

Using the shell is great for a powerful calculator, or for trying things out, but we don't normally write whole programs in it for a few reasons:

  1. It's hard to write a program one line at a time without being able to go back.
  2. If you make a mistake, you can't really "undo" an instruction.
  3. When you close the window, the code is gone.

For those reasons, we normally write programs in a file, and run the whole thing at once. To do this, click "File->New File" on the menu bar. This will open a second window:


The shell is on the left, our new file on the right

This window does not have the shell prompt (>>>). If we type a print message into it, it won't execute right away like it does in the shell.

Instead we have to run the whole file. To do this, click "Run->Run Module", or hit the F5 key. If the program has not been saved yet, it will ask you to save it. Make sure to save it some place you will be able to find it later!. After it's saved, the program will run in the shell window:


Successfully running a Python program


Task

For this lab you should create a Python program which prints your name to the screen. You can also add another print message, if you want to.

Be sure to write your program into a file and not the shell! You should save the file as something ending in .py, and run it using "Run->Run Module" to be sure that it works.


Submitting

When your program prints your name, email the .py file to ifinlay@umw.edu. Please attach it as a file instead of copying it into the body of the message!

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.