For this quiz I was given 46 simple python for me to do until the end of the semester. In this post I’ll show the first 5.

  1. Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Python. (It is true that Python has the max() function built in, but writing it yourself is nevertheless a good exercise.)

Captura de pantalla 2017-02-09 a la(s) 10.29.15.png

Captura de pantalla 2017-02-09 a la(s) 10.30.22.png

2. Define a function max_of_three() that takes three numbers as arguments and returns the largest of them.

Captura de pantalla 2017-02-09 a la(s) 10.43.03.png

Captura de pantalla 2017-02-09 a la(s) 10.43.17.png

3. Define a function that computes the length of a given list or string. (It is true that Python has the len() function built in, but writing it yourself is nevertheless a good exercise.)

Captura de pantalla 2017-02-09 a la(s) 10.51.13.png

Captura de pantalla 2017-02-09 a la(s) 10.51.27.png

4. Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise.

Captura de pantalla 2017-02-09 a la(s) 11.08.35.png

Captura de pantalla 2017-02-09 a la(s) 11.08.54.png

5. Write a function translate() that will translate a text into “rövarspråket” (Swedish for “robber’s language”). That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon".

Captura de pantalla 2017-02-09 a la(s) 11.03.44.png

Captura de pantalla 2017-02-09 a la(s) 11.04.05.png