ubuntu2004
Task 2.1
Ask for input of two integers: a numerator and a denominator.
Calculate and print their integer division and remainder.
Task 2.2
Using just a single print()
statement, print a table of two columns and three rows that resembles the following table of two crab species commonly found on the Scottish coast.
Hint: Use tab and newline escape characters.
Common name | Species name |
---|---|
Shore crab | Carcinus maenas |
Edible Crab | Cancer pagurus |
Task 2.3
Assign the string
TTTTGTATCCTTATATCACAACTCGAAGATTCTTCTTCTGCA
to the variabledna_seq
.Print the number of bases in
dna_seq
, i.e., find its length.
Task 2.4
Create the empty string
protein_seq
.Proteins are chains of amino acids of which there are 20. Add "M" (which is methionine) to end of
protein_seq
and print it, then add "A" (which is alanine) to the end and print it.
Task 2.6
Access the first to third characters in the variable
dna_seq
and assign them to the variablecodon1
.Next access the fourth to sixth characters and assign them to the variable
codon2
.Print
codon1
andcodon2
.
Task 2.7
Using a Python string method, convert the following DNA sequence into RNA. That is, replace thymine bases (T) with uracil bases (U).
Hint: We haven't covered this in the Notebooks so Google how to do it with "python replace character in string with another character".
Remove the spaces between the codons.
Hint: To remove a space character, what do you need to replace it with?
Task 2.8
Convert the following DNA sequence to uppercase and print it. Use Google if you need to.
Task 2.9
In the genetic code the codon "ATG" is the start codon which is used by the ribosome to initiate the synthesis of a protein.
The following DNA sequence contains the start codon "ATG".
Find its index and print it.
Using the index you just found, use string slicing to create a new sequence from the old sequence in which only the bases from "ATG" onwards occur.
Print the new sequence
Task 2.10
Using the in
comparison operator, test if "ATG" is in the following DNA sequence. Print the outcome.
Task 2.11
Using the find()
string method, test if "ATG" is in the following DNA sequence. Print the outcome.
Hint: Remember that
find()
returns -1 if a substring is not in a string (see Notebook 7).
Task 2.12
A word palindrome is a word which reads the same backward as forward, e.g., "level". In this task you will write code to test if a word is a palindrome.
Reverse the word in the following code and assign it to the variable
rev_word
.Test whether
word
andrev_word
are equal. If they are, use an f-string to print that the word is a palindrome.
Task 2.15
Ask for input of a year and test and print whether it is a leap year or not.
A leap year is divisible by 4, except for years which are divisible by 100 but not divisible by 400. For example, the years 1600 and 2000 are leap years, but the years 1700, 1800, and 1900 are not.
Hint: You may wish to use the modulus operator
%
(see Notebook 3).