CPSC 120 B




Lecture
MWF 10:50am - 11:50am
Lab
MWF 12:00pm - 1:00pm

Scotty Smith

Office
Trexler 365-B
Office Hours
Monday / Thursday
3:00pm - 5:00pm
Email
chssmithATroanoke.edu

< Back
Printable Copy

Lecture 4 - Naming Objects


As usual, create two directories for today's class. Create a directory called lecture4 under activities, and a directory called lab4 under labs.


Variables

Up until now, we have made some computation, and been done with it. However, most of the time we will want to keep track of the values we compute, for future use and references. Variables allow us to accomplish that.

Reserved Words


In-class Activity 1

Age in Seconds (Redux)

Create a Python program that prints your age in seconds. The program should use meaningful names for values and simple statements to make the program more readable.


In-class Activity 2

How Many Handshakes (Problem Solving)

In Emacs, create a Python program in a file called handshakes.py. The program should print how many handshakes it would take for every student at Roanoke to shake hands with every other student at Roanoke. Assume the number of students at Roanoke is 1,869. The program should use Python's arithmetic operations to perform the calculations and should print the number of handshakes nicely formatted and labeled.


Program Readability

Comments are not the only mechanism we can use in order to make our programs more readable. Choosing appropriate variable names, as well as following some simple guidelines can make it much easier to follow the intent of a program.

Formatting

Variables


In-class Activity 3

Oil Drum Volume

Create a Python program in a file called oil_drum.py that prints the volume of an oil drum in gallons if the drum's radius is 11.25 inches and the height is 33.5 inches. The volume of a cylinder can be computed using the equation, volume = area_of_base * height, and the area of a circle can be computed using the equation area = pi * r2. One gallon is 231 cubic inches.


Lab Assignment 4

Voyager 1

Voyager 1 is a space probe that was launched by NASA in 1977. It is currently the farthest man-made object from Earth.

In Emacs create a python program in a file called voyager.py. The program should print how long it takes a signal from Voyager 1 to reach the Earth and how long it would take voyager 1 to reach Proxima Centauri at its current velocity. These calculation should be performed using Python's arithmetic operations and printed nicely labeled and formatted. Be sure to use variables where appropriate, and make sure that you follow the coding guidelines described in class.

Currently, Voyager 1 is approximately 18,206,397,571 km from Earth. The Voyager 1 communicates with radio waves, which travel at the speed of light, 299,792,458 m/s. The Voyager 1's velocity is 61,400 km/h. The nearest star to the Earth is Proxima Centauri at 4.2 light years. Voyager 1's power comes from heat released by the radioactive decay of plutonium. It is projected that Voyager 1 will run out of power in the year 2025.

Make sure to include a comment header which lists who the authors are, as well as the purpose of the file.


Submission

When you have finished, create a tar file of your lab4 directory. You can do this by first navigating to your labs directory, using the cd command. Then, issue the following command.

tar czf tarfilename.tgz lab4/

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Lab Assignment 4. Only one of your pair should submit your activity. Make sure both partners are listed in the header of your file.


Last modified: Wed Sep 4 09:32:58 EDT 2013