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 12 - Test


This portion of the test is worth 40 total points. You may reference any files within your directory, as well as the Internet. As usual, you are not allowed to directly copy any code from the Internet without citation. You should also follow all coding standards discussed thus far.

Create a directory called test1 under cs120. Make sure all files you work on today are stored in this directory.

cd cs120
mkdir test1
cd test1

Question 6

Create a file called question_6.py. Put your answers to the following questions there.

(5 points each, 25 points total)


Question 7

My Pancreas

My pancreas attracts every other
Pancreas in the universe
With a force proportional
To the product of their masses
And inversely proportional
To the distance between them...

"Weird Al" Yankovic in Pancreas

Who would have thought that real physics would appear in such an absurd song? It's true, your pancreas does attract every other pancreas in the universe. The force is just incredibly weak. We might as well find out what that force is, anyways.

The gravitational force between two objects can be computed using the equation:

F = G × M1 × M2 / r2

Where the gravitational constant G = 6.673 × 10-11, M1 and M2 are the masses (in kg) of the objects in question, and r is the distance (in meters) between the centers of mass of the two objects.

Create a file called question_7.py, write a function to compute this gravitational force. Use this function to determine the gravitational attraction of your pancreas to your neighbors. Assume the average pancreas weighs 80 grams, and that your pancreas is about 1 meter away from your neighbor.

Of course, that information isn't very useful. However, the gravitational force between astronomical objects might be. The most massive object in our solar system is the Sun. With a mass of 1.981 × 1030 kg, its mass is over 300,000 times that of the Earth (5.97 × 1024 kg). Compute the gravitational force between the Sun and the Earth, assuming the average distance between them is 147 million km.

The Earth's orbit is not perfectly circular. The elliptical nature of the orbit causes the distance between the Earth and the Sun to vary by about 5 million km over the course of the year (about 2.5 million km in either direction). Using a for loop, print how this affects the gravitational force. You only need to print this change for every 1000 km.

(15 points)


Bonus

Fibonacci Sequence

The Fibonacci sequence is a famous mathematical sequence of numbers that is strongly related to the Golden Ratio. One of the wonders of the sequence is its exceedingly simple definition. Let Fn define the nth number in the Fibonacci sequence, where F1 = 1 and F2 = 1. Then, the nth number can be computed as: Fn = Fn - 1 + Fn - 2

Create a file called bonus_question.py. In this file, write a function called compute_fib, which takes a single parameter n, and uses a for loop to compute and ultimately return the nth number of the Fibonacci sequence.

(10 points)


Submission

When you have finished, create a tar file of your test1 directory. To create a tar file, execute the following commands:

cd ~/cs120
tar czvf test1.tgz test1/

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Test 1.


Last modified: Mon Sep 23 09:13:01 EDT 2013