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

Exercise 9.1

  1. Say we have three variables, x, y and z that store decimal numbers.

  2. Write some code to test and print whether y is between x and z.

Test your code on the following sets of numbers.

x = 12.3 y = 7.5 z = 3.6

and

x = -2.5 y = 7.5 z = 13.6

and

x = -2.5 y = 27.5 z = 13.6
x = -2.5 y = 27.5 z = 13.6 if (y < x and y > z) or (y > x and y < z): print('yes') else: print('no')
no

Exercise 9.2

  1. Ask for input of a word.

  2. Test and print whether either of the letters 'a' or 'e' are in the word.

word = str(input()) if 'a' in word or 'e' in word: print('yes') else: print('no')
yes

Exercise 9.3

  1. Ask for input of a DNA base (A, C, G, and T) in lower or upper case.

  2. First test that the input is a single letter rather than no input or more than one letter. Hint: Use len().

  3. If the test in Step 2 is True, next test if the letter entered is a valid base and not some other letter. Print whether the base is valid or not.

  4. If the test in Step 2 is False print that the input is not a valid base.

base = input() if len(base) == 1: if base == 'a' or 'c' or 'g' or 't': print('valid') else: print('not valid') else: print('not valid')
valid

Exercise 9.4

  1. Ask for input of an integer number.

  2. If that number is even (i.e., whether it is divisible by 2) print True otherwise print False.

x = int(input()) print(x % 2 == 0)
False

Exercise 9.5

  1. Ask for input of a word.

  2. If the letter "r" is in the word print True otherwise print False

word = str(input()) print(word.find('r') > -1)
False