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.
- 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 themax()
function built in, but writing it yourself is nevertheless a good exercise.)
2. Define a function max_of_three()
that takes three numbers as arguments and returns the largest of them.
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.)
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.
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"
.
This actually helped me a lot because I had some doubts about problem number five, thanks!
LikeLike
Me either! I was confused with the “return” part, i did not know how to make the function return me a value and also print it.
LikeLiked by 1 person
Thanks a lot Elu! I was confused with the last part of “__name__==__main__” but thanks for addresing my comments via phone thaks a lot!
LikeLike
Thank you! You really helped on that last one!
LikeLike
Hey man you really help me , i was lost in the return part your blog was very helpfull!
LikeLike