Lab 1: Basic Programming Elements

Introduction

The purpose of this lab is to learn the basic elements of writing computer programs in the Python programming language. This is not a comprehensive introduction to Python, but you will learn enough to get started. You may be new to programming, but don't be intimidated. Python has a very gentle learning curve.

To write our simulations, we must make use of certain tools made available by the Python programming language. This week, we will investigate how to manipulate variables and control the order in which our computer instructions are executed. We will also learn how to write output data to a file that can be opened by MS-Excel.

In the early going, you will be copying code directly from examples provided in the lab. Carefully read the comments in the computer code; they will provide further instructions.

Save your files on your local machine, in the scratch space directory (the drive letter is T). Create a special subdirectory for your work. Do not use the default directory provided by Python, or your files will be erased when the computer is restarted.

Learning Goals

At the end of this lab, you should have the following skills:

  1. Declare and manipulate a scalar variable in Python.
  2. Declare and manipulate a vector variable in Python.
  3. Use the augmented increment method of changing the value of a variable.
  4. Use a conditional branch to select what parts of the program are executed.
  5. Use a loop to cause sections of the program to be executed several times.

What To Turn In

At the end of the lab you should have five program files. Submit these to the Digital Dropbox on Blackboard.

Make sure you follow the filename convention described in this lab! (See Exercise 1.)

Exercises

Follow these links to the individual exercises. For each exercise, upload your program file to the Digital Dropbox on Blackboard. For the last exercise, also upload your CSV files.