Quiz - 11ΒΆ
Develop the function verb
that receives a string s
as a parameter. If the length of the string is at least 3, it should return the original string concatenated with "ing"
at the end. If the string s
already ends with "ing"
, concatenate the string "ly"
. If the length of the string is less than 3, it returns the original string.
Examples:
verb("singing")
-> "singingly"
verb("travel")
-> "traveling"
verb("do")
-> "do"
Develop the function is_not_bad
that receives a string s
as a parameter. The function must search for the first occurrence of the string "is not bad"
and the last occurrence of the string "bad"`, if either appears after the first one, replace ``"is not" ... "bad"
with the strings "is good"
respectively, then return the result.
Examples:
is_not_bad("The tea is not bad")
-> "The tea is good"
is_not_bad("The movie is not bad")
-> "The movie is good"
is_not_bad("This house price is not that bad")
-> "This house price is good"
is_not_bad("The phone is bad")
-> "The phone is bad"
Develop the function start_end
that receives two strings a
and b
. The strings have to be divided into two, if either of the strings has an odd number of characters, the first half will be the longest substring (for example dog
will be divided into: do
and g
). Given the two strings, return a new string formed as follows a_start + b_start + a_end + b_end
.
Examples:
start_end("abcd", "1234")
-> "ab12cd34"
start_end("abc", "1234")
-> "ab12c34"
start_end("abc", "123")
-> "ab12c3"
Develop the function how_many_zeros
that given a positive integer n
, returns the number of zeros at the end of the integer.
Examples:
how_many_zeros(10010)
-> 1
how_many_zeros(908007000)
-> 3
Develop the function count_2
that receives a positive integer n
greater than 0. The function must return the number of times the digit 2 appears in the interval``[0, n-1]``.
Examples:
count_2(20)
-> 2
count_2(5)
-> 1
count_2(1)
-> 0
Develop the function start_power
that receives a positive integer n
greater than 0. The function must return the first power of 2 that starts with n
.
Examples:
start_power(65)
-> 16
Explanation: for n = 65
the power of 2^16
results in 65536
which contains n
at the beginning.
start_power(4)
-> 2
Explanation: for n = 4
the power of 2^2
results in 4
which contains n
at the beginning.
start_power(3)
-> 5
Explanation: for n = 3
the power of 2^5
results in 32
which contains n
at the beginning.