< 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 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.


Question 6

Create a python program in a file called product.py. Your program should prompt the user for an integer \(n\), and print the product of all of the reciprocals from 1 to \(n\): \[ \prod_{x = 1}^{n} \frac{1}{x} = \frac{1}{1} \times \frac{1}{2} \times \ldots \times \frac{1}{n} \]

Example

$ python3 product.py
How many terms? 3
0.166666666666666666666

Question 7

Write a python program that prompts the user to enter a number of squares, and uses Turtle graphics and a for loop to draw the specified number of concentric squares. There can be any distance between squares, but each square must be centered inside the square that surrounds it.

Example

$ python3 concentric.py
How many terms? 10

Bonus

Write a python program which uses uses Turtle graphics and for loops to draw a number of overlapping rings in a pyramid shape as shown below. It can appear anywhere on the screen, but must contain at least 10 rows, with one additional circle per row. You can use the turtle.circle function to draw a circle on the turtle screen.

Example


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