Intro to Python Homework

  • Write a line of code that stores the value of the $atan(5)$ in the variable y.

In [ ]:

  • In words, what the math.ceil and math.floor functions do?

In [ ]:

  • Store the result of $5x^{4} - 3x^{2} + 0.5x - 20$ in the variable y, where $x$ is 2.

In [ ]:

  • Construct a conditional that prints $x$ if it is smaller than 20 but greater than -5

In [ ]:

  • Construct a conditional that prints $x$ if it not between 5 and 12.

In [ ]:

  • What will the following code print? (Don't just copy and paste -- reason through it!)


In [ ]:

  • Write a loop that prints every 5th number between 1 and 2000. (HINT: try help(range))

In [ ]:

  • What will the following program print out?


In [ ]:

  • Write a loop that calculates a Riemann sum for $x^2$ for $x \in [-5,5]$.

In [ ]:

  • Create a list of all integers between 2 and 30.

In [ ]:

  • Create a list called some_list that has all sin(x) for x $\in$ [$0$, $\pi/4$, $\pi /2$, $3 \pi /4$... $2 \pi$].

In [ ]:

print(some_list)

[100,-99,98,-97,96,...,0]

In [ ]:

  • Write a loop that creates a dictionary that uses the letters A-E as keys to the values 0-4.

In [ ]:

  • Create a $3 \times 3$ list of lists with the integers 0-8:

    [[0,1,2],
       [3,4,5],
       [6,7,8]]
    

    Multiply the whole array by 5 and then take the natural log of all values (elementwise). What is the sum of the right-most column?


In [ ]:

  • Repeat the exercise above using a numpy array. Use a numpy array to calcualte all sin(x) for x $\in$ [$0$, $\pi/4$, $\pi /2$, $3 \pi /4$... $2 \pi$].

In [ ]:

  • Write a function that takes a string and returns it in all uppercase. (Hint, google this one)

In [ ]:

  • Use matplotlib to plot $sin(x)$ for x $\in$ [$0$, $\pi/4$, $\pi /2$, $3 \pi /4$... $2 \pi$]. Use both orange points and a green line.

In [ ]:

You measure the doubling times of bacterial strains A-D under identical conditions.

strain doubling time (min)
A 20
B 25
C 39
D 53

Assuming you start with a single cell and have nutrients in excess, you can calculate the number of bacteria $N(t)$ in a culture after $t$ minutes according to:

$$N(t) = 2^{t/d}$$

  • Write a function called num_bacteria that takes the time and doubling time and returns the number of bacteria present.

In [ ]:

  • Create a dictionary called doubling that keys the name of each strain to its population after 12 hours.

In [ ]:

  • Use matplotlib to create a single graph that shows $N(t)$ for all four bacterial strains from 0 to 18 hr. Make sure you label your axes appropriately.

In [ ]: