Quiz - 11¶
Develop the function verbo
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:
verbo("singing")
-> "singingly"
verbo("travel")
-> "traveling"
verbo("do")
-> "do"
Develop the function no_es_malo
that receives a string s
as a parameter. The function must search for the first occurrence of the string "no es"
and the last occurrence of the string "malo"
or the string "mala"
, if either appears after the first one, replace "no es" ... "malo"
or "no es" ... "mala"
with the strings "es bueno"
or "es buena"
respectively, then return the result.
Examples:
no_es_malo("El té no es malo")
-> "El té es bueno"
no_es_malo("La película no es mala")
-> "La película es buena"
no_es_malo("El precio de esta casa no es para nada malo")
-> "El precio de esta casa es bueno"
no_es_malo("El teléfono es malo")
-> "El teléfono es malo"
Develop the function inicio_final
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:
inicio_final("abcd", "1234")
-> "ab12cd34"
inicio_final("abc", "1234")
-> "ab12c34"
inicio_final("abc", "123")
-> "ab12c3"
Develop the function cuantos_ceros
that given a positive integer n
, returns the number of zeros at the end of the integer.
Examples:
cuantos_ceros(10010)
-> 1
cuantos_ceros(908007000)
-> 3
Develop the function contar_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:
contar_2(20)
-> 2
contar_2(5)
-> 1
contar_2(1)
-> 0
Develop the function inicio_potencia
that receives a positive integer n
greater than 0. The function must return the first power of 2 that starts with n
.
Examples:
inicio_potencia(65)
-> 16
Explanation: for n = 65
the power of 2^16
results in 65536
which contains n
at the beginning.
inicio_potencia(4)
-> 2
Explanation: for n = 4
the power of 2^2
results in 4
which contains n
at the beginning.
inicio_potencia(3)
-> 5
Explanation: for n = 3
the power of 2^5
results in 32
which contains n
at the beginning.