< Back

Test 1

Create the following directories for storing your answers to today's test. Make sure all of the files you create are stored within this directory.

$ cd ~/cs120/
$ mkdir test1
$ cd test1

You are only allowed to access this course webpage, the Python and Turtle documentation webpages. You are not allowed to access any other websites. You may access any python files within your personal home directory. You are not allowed to access files of any other type, or files from any other user's directories. Failure to abide by these rules is a violation of Academic Integrity, and will be treated as such.


Question 7

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

(3 points each, 15 points total)


Question 8

Half-lives

Radioactive materials experience radioactive decay. This results from the atoms of the material emitting particles as radiation. Over time, this radiation reduces the amount of material that is still present. A common measurement of this phenomenon is deemed "half-life." Half-lives for common materials can be found on Wikipedia.

Create a file called question_7.py that contains a function called compute_duration(material_amount, half_life). The material_amount parameter is the amount of material in grams, while the half_life parameter is the time (in seconds) that it takes for half of the material_amount to decay by half.

This function should compute (and return) the duration (in seconds) that the material will continue to exist. You can compute this value by multiplying the half-life by: $$ log_{2}\left( \frac{amount}{EPSILON} \right)$$ where EPSILON is a constant with value 0.000001. Remember that you can use the log function from the math module to compute logarithms.

In the same file, use the function you wrote to complete (by printing out) the following table.

Material Amount Half-Life Duration
Plutonium-238 200 kg 2.77 × 10 9 seconds
Iodine-131 400 kg 6.912 × 10 5 seconds
Caesium-137 5,500 kg 9.4 × 10 8 seconds
Beryllium-11 10 g 13.81 seconds

(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:

$$F_{n} = F_{n - 1} + F_{n - 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.


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 inquire.roanoke.edu. You should see an available assignment called Test #1.