#Quiz05

  • 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.)

Screen Shot 2017-02-09 at 6.36.38 pm.png

For this, you only need to define the function called largest_number, and use the build-in function max() in python. Then ask the user for two numbers, and the function gives you the largest of the two numbers.

 

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

Screen Shot 2017-02-09 at 6.43.47 pm.png

Same thing as above, but you just need to add a third variable!

 

  • 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.)

Screen Shot 2017-02-09 at 6.46.03 pm.png

Here you need to define a function called length_of_string, then return the Python build-in function len(). Ask the user for a sentence (and do not forget to convert the sentence into a string). The functions returns you the number of characters in your sentence.

 

 

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

Screen Shot 2017-02-09 at 6.49.24 pm.png

You need to ask the user for a letter. Then use the conditional execution if .. in ( “a”, “e”, “i”, “o”, “u”), in order to detect a vowel. Else will detect other characters which are not vowels. I found this website helpful for this question: http://stackoverflow.com/questions/20226110/detecting-vowels-vs-consonants-in-python

 

  • 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".

Screen Shot 2017-02-09 at 6.59.23 pm.png

This was the hardest question. You need to define a function that I called translate_sweedish with the argument string (which is the sentence asked to the user). The function is composed by a conditional execution similar as above, detecting if the letter is a vowel or not. If the letter is a vowel, the letter stays still. However, if the letter is not a vowel, the letter is doubled and has an occurrence of o in between. Thus, the function returns a really weird sentence!

 

Leave a comment