Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Task 1.1

Using Python code, convert 50 inches into centimetres and print the result using an f-string so the output reads:

50 inches is X cm

where X is your answer.

  • Hint: If you can't remember how many centimetres in an inch, google it.

print( f'50 inches is {50*2.54} cm')

Task 1.2

Using Python code, convert 50 inches into feet and inches and print the result using an f-string so the output reads:

50 inches is X feet Y inches

where X and Y are your answers.

  • Hint: Use integer divison and remainder.

print( f'50 inches is {50 // 12} feet {50 % 12} inches')

Task 1.3

How do you think you could use Python code to indicate if an integer number is odd or even?

Hint: Think what makes an integer odd or even. Then think which arithmetic operator could be used to give you one answer for even and another answer for odd.

Use Python code to test if zero odd or even?

(We will use this code later when calculating the median of a set of data.)

# An even number is divisible by 2, so the remainder of an even number divided by 2 is 0 # An odd number is not divisible by 2, so the remainder of an odd number divided by 2 is 1. # The statement "number % 2" will indicate whether a number is odd or even. # Zero is even as 0 % 2 is 0. 0 % 2

Task 1.4

Video answer>

Add a print statement with an f-string to the code below to print the following statement:

The percentage of land covered by forest is 1.06%

You should perform the calculation within your f-string. Round your answer to 2dp.

Google how to format a decimal number to a percentage without multiplying by 100.

total_land_area = 89032840.42390 forest_area = 939402.42445 print( f'The percentage of land covered by forest is {forest_area/total_land_area:.2%}' )

Task 1.5

Which of these variable names should not be used and why?

  1. test

  2. Len

  3. surname

  4. ph

  5. 0_value

  6. lambda

  7. alpha

  8. O

  9. cell_concentration

  10. dna_seq

Variable namevalidreason
testyes
Lennosimilar to len()
surnameyes
phyesshort, but maybe okay
0_valuenostarts with a number
lambdanoPython reserved word
alphayes
Onotoo similar to zero
cell_concentrationyes
dna_seqyes

Task 1.6

Video answer>

Bacterial cells replicate by binary division. Under conditions of ample resources, the number of bacteria in a population grows exponentially.

If we wish to predict the size of a population of bacteria after a given time from a starting population we can use the formula

Nt=N02t/d\begin{equation} N_t = N_02^{t/d} \end{equation}

where Nt is the population size after time t, N0 is the starting population size at time t = 0, and d is the average time it takes between bacteria replications; also known as the doubling time.

The units of t and d must be the same (e.g. hours or minutes).

Let the starting population be 450 bacteria and the doubling time be 20 minutes. How many bacteria are there after 12 hours? Your calculation should be performed entirely with Python code.

N0 = 450 d = 20 t = 12*60 # Convert t to minutes print( N0 * 2**(t/d) )

Task 1.7

Video answer>

Each bacterium has a mass of approximately 170 femtograms, which is 1.7x10-13 g or 1.7e-13 g in scientific notation. What is the mass of the bacterial culture after 16 hours?

N0 = 450 d = 20 t = 16*60 # Convert t to minutes N = N0 * 2**(t/d) mass = 1.7e-13 print( f'{mass*N:.1f}' )

Task 1.8

Video answer>

When the wind blows in cold weather, the air feels colder than it actually is because the movement of the air increases the rate of cooling for warm objects, like people. This effect is known as wind chill.

This is the formula for calculating wind chill (the temperature it feels like)

wind chill=13.12+0.6215×T11.37×V0.16+0.3965×T×V0.16\text{wind chill} = 13.12 + 0.6215\times T − 11.37\times V^{0.16} + 0.3965\times T\times V^{0.16}

where T is the air temperature in degrees Celsius and V is the wind speed in kilometres per hour.

Write some code to calculate wind chill using the variables T and V below. Round your answer to 1dp.

T = 5 V = 10 wind_chill = 13.12 + 0.6215*T - 11.37*V**0.16 + 0.3965*T*V**0.16 print( f'{wind_chill:.1f} deg C' )