CPSC120
Fundamentals of Computer Science

Activity 7

Reassignment

Spiral

The human visual system did not evolve to perceive the types of regular patterns that are simple to create with programming. A spiral of contrasting colors can produce the illusion of motion when you move your eyes over the static image.

Details

Create a Python program that uses turtle graphics to draw a square spiral. The program should prompt the user to enter the amount that each line is longer than the previous line that was drawn. The program can have any number of lines, but more lines look cooler. Again, you can write this program without variable updating. For the sake of practice, write it using a variable for the distance that the turtle moves that is repeatedly updated.

Example

Enter the line increase amount:

10

square spiral

Hint

  • To draw the square spiral the turtle should repeatedly move forward and turn.
  • The turtle should always turn 90°.
  • The distance forward the turtle moves should increase with each line. Create a variable for the distance the turtle moves and update the variable’s value before drawing each line. Use the value entered by the user as the amount the variable increases by.

Change

Many people would call me a lazy person. I don't find that offensive, but I think it 's not an accurate description. It 's not that I'm lazy, I just try to be as efficient as possible. For example, in college, a group of friends and I deduced the fewest coins to carry that would produce any arbitrary amount of change. While a computation like that is still a little too complicated, figuring out the fewest amount of coins for a fixed amount of change is possible.

Details

Create a Python program that reads a number of cents from the user and prints the fewest number of coins, using pennies, nickels, dimes, and quarters needed to make change. You can assume that the number of cents entered by the user will be between 0 and 100.

Example

Enter cents:

93

92 cents is:

3 quater(s)

1 dime(s)

1 nickel(s)

3 penny(s)

Hint

  • You can use integer division (//) to determine how many times a coin goes into the change amount evenly. For example, ’92 // 25` is 3, so 3 quarters go into 92 cents evenly.
  • You can use the mod (%) operator to determine the remainder. Use mod with variable updating to determine the number of cents that are left after coins are removed. For example, ’92 % 25` is 17, so 17 cents are left after taking 3 quarters out of 92 cents.
  • Start with the largest coin first (quarters) and work your way down. This is known as a greedy approach and is very common in Computer Science.

Challenge

Modify the change program so that it works for dollars as well. The program should read an amount of money as a float and print the fewest number of bills and coins that are equivalent to the entered amount.

Enter dollars:

237.93

237.93 dollars is:

2 hundred(s)

0 fifty(s)

1 twenty(s)

1 ten(s)

1 five(s)

2 one(s)

3 quater(s)

1 dime(s)

1 nickel(s)

2 penny(s)