Paired Programming Activity
Loop Problems, part 1

Activities

I would like you to attempt to complete several small Python functions working with your partner.

Please try to make your program output look as much like the example as possible and verify it works with the example input provided. If you have difficulty finding the information or understanding how to approach the problem, you should contact me.

To complete this activity, you will need to create the following scripts:

 

 


LOOP 0

Santa put Kohls in your stocking

If you have ever shopped at one of those stores like Kohls that seems to have CONSTANT sales, you will now that they often have signs showing you the original price of the item and the sales price of the item.  If there are lots of items with different prices they will often print a table of multiple items.

Write a Python function that conforms to the following:


LOOP 1

I have a conjecture

According to Wikipedia, "The Collatz conjecture is one of the most famous unsolved problems in mathematics. The conjecture asks whether repeating two sipmle arithmetic operations will eventually transofrm every positive integer into 1." It is named after mathematician Lothar Collatz who first introcued the idea in 1937

The process is as follows:

Then you continue this process on the new number repeatedly until you finally arrive at the number 1.

For example:

f(3) = because 3 is odd we take 3*n+1 or 3*3+1 = 10
f(10) = because 10 is even we take n/2 or 10/2 = 5
f(5) = because 5 is odd we take 3*n+1 or 3*5+1 = 16
f(16) = because 16 is even we take n/2 or 16/2 = 8
f(8) = 4
f(4) = 2
f(2) = 1

In other words, it took us 7 moves to go from 3 to 1.

While it hasn't been officially proven yet, Collatz has proposed that EVERY positive integer will eventually work its way to 1.

Write a Python function that conforms to the following:


LOOP 2

TC Works for the UNI Foundation

TC has started working for the UNI Foundation.  One of the ways that UNI is able to give scholarships is off of the interest from smart, long-term investments.  They are trying to figure out how long it will take them to double their money in particular investments.

 

NOTE: This is a loop problem. You must use a loop to get credit. DO NOT simply use a formula.


LOOP 3

It's a Growing Problem

NOTE: This is a challenge problem.
I think it is a great example of a basic loop problem.
BUT, the math in it is a bit tricky and requires you to put together some things we have done in very different ways.
The challenge isn't the loop - it's the math that controls the loop. I encourage you to give it an honest try and then
watch the video to see how I would solve it.

 

Steph Infection is a biologist who is studying the generation time of various bacteria.

In biology the generation time is the time it takes for a population to double in size. For example, when E Coli bacteria are placed in a favorable medium, such as Glucose salts, they have a generation time of approximately 20 minutes.

Steph wants to be able to calculate how many bacteria she should expect to find in her petri dishes after a certain amount of time.

 

Write a Python function that conforms to the following: