Refresher exercises

This script contains exercises to repeat topics learned during the "Introduction to programmin with Python" course.

The scripts from this course are avaible at https://siscourses.ethz.ch/python_dbiol

if-elif-else, while and for

  1. Write a program which asks the user for a number and checks if the number is positive, negative or zero and prints an appropriate message

  2. Implement https://www.wikiwand.com/en/Fizz_buzz#/Play up to 50.

  3. Write a program which asks the user for a number n and then computes the sum 1 + 2 + ... + n.

  4. Implement a number guessing game: the computer creates a random number in the range 1 to 100 and asks the user to guess until the user finds the number. If the number is not correct, the computer prints a message if the guess is to low or to high.

  5. Redo the collatz iteration exercise 5.3 of script https://siscourses.ethz.ch/python_dbiol/04_looping.html

Working with strings

  1. Write a program which computes the relative GC content of a given sequence of symbols ATGC.
  2. Extend 2 to ignore the case of the symbols in the input.
  3. Extend 3 to ignore invalid symbols in the input.
  4. Repeat https://siscourses.ethz.ch/python_dbiol/05_sequences.html#The-find-method-of-strings
  5. Write a script which reverses a given string
  6. Write a script which checks if a given string is a palindrome (the reverted string is the same string)

Functions

  1. Write a function sum_up_to(n) which takes an integer number n and returns the sum 1 + 2 + ... n.

  2. Write a function collatz_count(n) which counts the number of collatz iterations needed to reach 1 starting with n (see also exercise 5.3 of script https://siscourses.ethz.ch/python_dbiol/04_looping.html)

  3. Write a function collatz_values(n) which returns a list of numbers of the collatz iterations starting with n.

  4. Write a function is_prime(n) which returns True if given n is prime else False.

  5. Write a function filter_even(li) which takes a list li of integer numbers an returns a list containg the even numbers of li.

  6. Write a function revert(txt) which reverts a given string txt.

  7. Write a function is_palindrome(txt) which returns True if txt reads backwards as forwards, else False.

Files

  1. Write a program which writes 10 random integer numbers to a text file, one number per line
  2. Write another program which reads those numbers and computes their sum
  3. Write a program which reads the result from 1. and writes a new file containing the squares of the even numbers in the input file.
  4. Repeat https://siscourses.ethz.ch/python_dbiol/06_introduction_to_files.html#Handling-csv-files-with-Python
  5. Write a program which writes a csv file with a sheet of size 10 rows and three columns with random integer numbers
  6. Read the numbers from this csv file and compute the columnwise sums
  7. Redo https://siscourses.ethz.ch/python_dbiol/06_introduction_to_files.html#Exercise-block-5

Lists

  1. Write a program which computes a list with the first 100 prime numbers.
  2. Write a function which checks if all numbers in a given list are prime.
  3. Write a function which checks if at least one number in a given list is prime.
  4. Write a program which computes a list x_values = [0, 0.1, 0.2, ... 6.2] and y_values with the $sin$ of the x_values. Then use matplotlib to plot this data.
  5. The Fibonacci sequence starts with numbers 1, 1, then every number after the first two is the sum of the two preceding ones. So the sequence is 1, 1, 2, 3, 5, 8, 13, ... Compute the first 100 numbers of the Fibonacci sequence using a list + for.
  6. Repeat https://siscourses.ethz.ch/python_dbiol/07_container_types.html#Splitting--strings until exercise block 3 included.

Dictionaries

  1. Repeat https://siscourses.ethz.ch/python_dbiol/07_container_types.html#Introduction-to-dictionaries up to exercise block 7 (included)
  2. Manually create a csv file with two columns: the first column contains one letter symbols of amino acids, the second the according three letter columns. Then build a dictionary for mapping one to three letter codes by reading the content of the csv file.
  3. Write a function which takes a sequence of one letter codes and translates this to a sequence of three letter codes.