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 test2 $ cd test2
You are only allowed to access this course webpage and the Python and Turtle documentation webpages. You are not allowed to access any other websites. You are not allowed to access files from your directory, 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.
In a file called question_8.py, write a function
called harmonic_progression(a, d, n)
,
which computes the sum of the harmonic progression defined by the
equation:
Function Call | Expected Value |
---|---|
harmonic_progression(1, 0, 1) | 2.0 |
harmonic_progression(1, 0, 2) | 3.0 |
harmonic_progression(1, 0, 3) | 4.0 |
harmonic_progression(1, 1, 2) | 1.8333333333333333 |
harmonic_progression(1, 1, 3) | 2.083333333333333 |
harmonic_progression(2, 2, 3) | 1.0416666666666665 |
(15 points)
In a file called question_9.py, write a function called
fizz_buzz(some_number)
. This function should print all
of the numbers from 0 to some_number. However, instead of
multiples of 3 your program should print "Fizz", and for multiples
of 5 your program should print "Buzz". For numbers which are
multiples of 3 and 5, print the string "FizzBuzz".
>>> fizz_buzz(10) FizzBuzz 1 2 Fizz 4 Buzz Fizz 7 8 Fizz
(15 points)
This is a very common job interview question, to weed out people who put "Computer Science" on their resumes, but do not have the technical skill to back that claim up.
In a file called question_bonus.py, write a program which uses the graphics module to display two bouncing balls on the screen. Each of these balls should bounce off the walls, and should bounce off each other.
(5 points)
When you have finished, create a tar file of your test2
directory. To create a tar file, execute the following commands:
cd ~/cs120 tar czvf test2.tgz test2/
To submit your activity, go to inquire.roanoke.edu. You should
see an available assignment called Test #2
.