ubuntu2004
Exercise 8.1
Assign the decimals 17.5 and -34.6 to the variables
x
andy
respectively.Test if
x
is greater thany
and print whether it is or not.
Hint: Use
if
...else
.
Exercise 8.2
The wavelength of visible light ranges from 380 to 750 nanometers (nm). While the spectrum is continuous, it is often divided into 6 colors as shown in this table:
Colour | Wavelength (nm) |
---|---|
Violet | 380 to less than 450 |
Blue | 450 to less than 495 |
Green | 495 to less than 570 |
Yellow | 570 to less than 590 |
Orange | 590 to less than 620 |
Red | 620 to 750 |
Write some code that asks for input of a wavelength and prints its corresponding colour. Display an appropriate error message if the wavelength entered is outside of the visible spectrum.
Hint: Use
if
...elif
...else
with oneelif
for each colour.
Exercise 8.3
Ask the user to input a word.
Test and print whether the letter 'e' is in the word or not.
Exercise 8.4
Modify Exercise 8.3 so that if e
is in the word the index of its first occurrence is printed, otherwise print that it is not in the word.
Hint: See Notebook 7 on how to find the index of a character.
Exercise 8.5
Ask for input of an integer.
Test and print whether the integer is odd or even.
Hint: In Task 1.3 of Workshop 1 we asked what arithmetic operator could be used to test if an integer was odd or even?
Exercise 8.6
Access the second to the last characters in the following variable
protein_seq
and re-assign them to the same variable.Print
protein_seq
.
Exercise 8.7
During protein synthesis methionine is the first amino acid of a protein sequence. After translation proteins are modified, one of these modifications is removal of methionine from the start of the protein sequence. However, this is more likely if the second amino acid in the sequence is an alanine.
Write some code to test if the second amino acid in each of the following two protein sequences is alanine (A). If it is modify the protein sequence to remove methionine (M). If it isn't do not change the protein sequence.
Print the resulting protein sequences.