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.
Create a file called question_6.py
. Put your answers to
the following questions there.
(3 points each, 15 points total)
Create two variables named current_year
and birth_year
. Store the current year and your birth
year in the proper variables.
Using these variables, write an expression to print your current age.
Write a function age_in_leap_years
, which takes a
single parameter representing the age of the requester, and prints
an estimate of how old they would be assuming they were born on
Feb. 29th. Assume that a leap year has occurred
every 4 years since their birth.
Use this function to print how old you would be if you were born on Feb. 29th.
Write a function compute_circle_area
. This
function should take one parameter, the radius of a circle. It
should return the area of a circle with the specified radius.
Recall the area of a circle can be computed using the following equation:
Using this function, print the area of a circle that has a radius equivalent to your (actual, not leap year) age you computed above.
Using the circle
method from the turtle
module, draw a circle with the radius you used above centered
around (0, 0).
Write a function called circumscribe_circle
, which
takes three parameters: the center x coordinate, the center y
coordinate, and the radius of the inscribed circle. This
function should use a for loop to draw a square which
circumscribes the circle that is specified in the formal
parameters of the function.
Using this function to draw a square around the circle drawn above.
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)
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:
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.
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
.