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

Exercise 4.1

Assign the value of 45 to the variable named number_of_flies.

number_of_flies = 45

Exercise 4.2

Print out the type of the variable number_of_flies.

number_of_flies
45

Exercise 4.3

Increment the variable number_of_flies by 12 and print its new value.

number_of_flies += 12 number_of_flies
57

Exercise 4.4

Scientists counted the number of emperor penguins that joined an Antarctic breeding colony on each day for a whole season. The first three day's records are given in the following table

DayNew colonists
1st March10
2nd March156
3rd March73

Using a variable called number_penguins print out the cumulative number of penguins in the colony on each of the first three days. Use the operator += to increment the variable.

number_penguins = 10 print(number_penguins) number_penguins += 156 print(number_penguins) number_penguins += 73 print(number_penguins)
10 166 239

Exercise 4.5

Each strand of DNA is made up of four bases: thymine (T), adenine (A), guanine (G) and cytosine (C).

The GC content of a strand of DNA is the percentage of bases that are either guanine or cytosine. The GC content can vary widely between different regions of an organism's genome and also varies widely between different organisms. GC content is often of interest to biologists as it can indicate the presence of DNA that may have originated from another organism's genome.

Complete the following code to calculate the GC content of a particular DNA sequence and print its value to 1dp.

# Assign the length of the DNA sequence (in base pairs) to the variable dna_length. dna_length = 14512 # Assign the number of bases that are either G or C to the variable number_GC_bases. number_GC_bases = 8534
# Calculate the percentage of bases that are either G or C and assign to the variable percentage_GC. percentage_GC = (number_GC_bases/dna_length)*100 # Print the value of percentage_GC to 1dp. print(round(percentage_GC, 1))
58.8

Exercise 4.6

Complete the code below using an f-string to insert the string variables into the printed string.

mean_beak_depth_mm = 9.27874 max_beak_depth_mm = 11.128392 min_beak_depth_mm = 7.689485 # Change the following string below to an f-string with all values rounded to 2 decimal places. print(f"Beak depth measurements of Ground Finches ranged from {max_beak_depth_mm:.2f} mm to {min_beak_depth_mm:.2f} mm, with a mean of {mean_beak_depth_mm:.2f} mm")
Beak depth measurements of Ground Finches ranged from 11.13 mm to 7.69 mm, with a mean of 9.28 mm

Exercise 4.7

Using the variable Fahrenheit below, write code to convert it to degrees Celsius and print the answer to 1dp. The conversion equation is

Celsius=59(Fahrenheit−32)\text{Celsius} = \frac{5}{9}(\text{Fahrenheit}-32)

Fahrenheit = 98 celsius = 5/9*(Fahrenheit - 32) print(round(celsius, 1))
36.7