CPSC120A
Fundamentals of Computer Science I

Lab 10

Test 1 Review

Use the command line to create a new directory called lab10 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Programming Exercises

For review for Friday, answer the following programming questions:

  1. Write a function sum_powers(n), which computes the sum of the numbers in the set:
    $$\{x^{x} \mid 0 < x \leq n\}$$
    Which in sigma notation is:
    $$ \sum\limits_{x=1}^{n} x^x = 1^1 + 2^2 + 3^3 + \ldots + n^n$$
  2. Write a function calledcompute_product(n), which computes the series:
    \[\prod\limits_{x=2}^{n} \frac{x}{x-1} = \frac{2}{1} \times \frac{3}{2} \times \frac{4}{3} \times \ldots \times \frac{n}{n-1}\]
Fish

Since we have a test on Monday, lets do a little bit of a fun activity. One of the badges of honor for the CS major comes from the CS120 class: drawing a fish. This activity was originally created by Dr. N. Jane Ingram and Dr. Adrienne Bloss for their Java labs in the 2000's. We are keeping their tradition alive today.

Details

Create a function draw_fish_at(x, y) in a file called fish.py. This function takes two integers as parameters, which is the location on the turtle window to draw a line drawing of a fish. Your fish should be drawn centered on the specified coordinate.

Start on paper first!. The activity will progress much easier for you if you figure out the coordinates of various points before you begin coding. Start with a plan and your code will come together very quickly.

Make sure to test your function by calling the function multiple times with different parameters. Make sure your code follows the course's code conventions.

Example

Hint

While this looks very complicated, it's just two partial circles and three lines. You just need to figure out the locations of certain points before you get started. Consider the following image if you need assistance:

Where the fish is 3 × r pixels wide from tail to the tip of the head.

Challenge

What do you call a fish with no eyes? FSH! Add eyes to your fish so it won't accidentally swim into a dam!

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.