--Originally published at Hello World
- 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.)
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.
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.)
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.
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
Continue reading "#Quiz05" →