Laboratory 1 – Getting Started with Python; Simple Arithmetic
Computer Science 222
1. Understand the editing and execution phases of a computer
2. Be able to execute a Python program using the IDLE integrated
development environment (IDE).
3. Interact with simple Python programs that produce output and do
4. Enter new programs using the IDLE editor.
1. Log on to the computer
using your Cougars account information.
a. Create a folder
named “Lab01” on the Desktop.
2. Open your WebCT account
for this course (e.g CSCI 222-L01).
You can get to
WebCT from the CofC webpage. Open a web browser and go to www.cofc.edu.
a. On the Homepage, select Labs, and select the one entitled Lab01 (click
on the title Lab01).
b. Under Assignment files, in the Files box, you will see two files.
Click on “First.py”.
c. In the View Files window, you’ll see the file name again. Click
on the circle in front of it and then press the Download button.
d. When asked, choose to "Save" the file and store it on
the Lab01 folder on your Desktop of your computer. This will place the file on
your computer's desktop. You should see the file named "First.py".
(Today we’ll work on the Desktop – starting soon, you will have your own disk
space available on these lab computers.)
3. Open and execute your
first Python program using IDLE.
a. Open the IDLE integrated development environment (IDE) by
double-clicking on the icon labeled IDLE.
b. On the IDLE toolbar, choose File,
then Open, and navigate to the
Desktop. Select the file named "First.py" (it may or may not show
an extension of "py") on the Desktop.
c. Double click (left mouse button) on the "First.py"
file and an editing window will open and display the code in that program. The
top of the edit window displays the name of the program ("First.py".)
d. Replace the text <your
name goes here with your name.
e. To execute the program, from the Run menu select Run module. Or simply press the F5 key.
This opens the Python Shell window that displays the output of the program –
the message "Programming is fun but is not a spectator sport!" (a
word to the wise).
f. Go back to the editor window. Change the message (stuff in
quotes) so that the program prints out "I look forward to learning to
control this computer through programming!" Save by pressing Control-S.
Execute your program, following instructions from part (e).
You’ll be asked to upload this program to
WebCT later, so don’t change it any more.
4. Enter a new program
using the editor.
case-sensitive, so type caps when you see caps and lower-case letters when you
see lower-case letters.)
a. From the File menu, select New
Window. Type in the following exactly as you see it there, except replace <your name
goes here with your name.
## <your name goes
num1 = 7
num2 = 5
answer = num1 + num2
print "Sum =", answer
b. Once you have typed the complete program, press "Control-S"
and save the program as SimpleArithmetic.py. Run it
by pressing F5. If you see an error message, you typed something incorrectly.
Compare the printout above with your program and fix any discrepancies found.
If you cannot find the error, ask the instructor for assistance. (Computers are
very picky about how programmers express things, and do not tolerate typos.)
Continue this process until the program runs successfully.
You’ve successfully entered and executed your first complete Python program.
Writing your own programs.
Write a program
similar to the one above that subtracts two numbers and prints the
difference. Call this program SimpleDifference.py.
Writing your own program.
Write a program
to calculate the volume of a rectangular solid.
The user of the program will provide the length, width and height of the
box. Call this program BoxArea.py.
7. Upload the files to
WebCT under the Assignments section:
SimpleDifference.py _______ BoxArea.py _______
You must press
the SUBMIT button or the uploaded
programs will not be submitted to the professor’s account.
Remove from the
desktop any files and folders you created (that should include the First.py that
you downloaded – mail them to yourself if you wish to have a copy.) Then, empty
your recycle bin. Log out of your Cougars account.
Log off of the computer you are using.
You'll get 1 file (1.0KB)