Quiz - 10

Develop the function cuantas_donas that takes n, a positive integer, as a parameter, and returns a string in the form of "Number of donuts: n", where n is the value passed to the function as an argument. However, if n >= 10, cuantas_donas will return "many" instead of n.

Examples:
cuantas_donas(5) -> "Number of donuts: 5"
cuantas_donas(23) -> "Number of donuts: many"

Develop the function cadena_de_extremos that, given a string s, returns a string with the first two and last two letters of s. However, if the string has less than 2 letters, it returns an empty string.

Examples:
cadena_de_extremos("palmeras") -> "paas"
cadena_de_extremos("a") -> ""

Develop the function remplazar_primer_caracter that, given a string s, returns a string in which all occurrences of the first character in s are replaced by “*”, except for the first one. Note: use the method .replace(value_to_replace, new_value) to solve the exercise.

Examples:
remplazar_primer_caracter("google") -> "goo*le"
remplazar_primer_caracter("dona") -> "dona"

Develop the function combinar_dos_cadenas that takes two strings as arguments, a and b, and returns a new string in the following way:

  • The new string has to be a combination of a and b.

  • The new string will have the form "<a> <b>", note the space between both.

  • The new string will interchange the first two letters of a and b.

Suppose that a and b have more than 2 characters. For better clarification, see the following examples.

Examples:
combinar_dos_cadenas("mix", "pod") -> "pox mid"
combinar_dos_cadenas("pezzy", "firm") -> "fizzy perm"

Develop the function es_palindromo that takes a string s as parameter and checks if s is a palindrome or not, returning True or False accordingly.

Examples:
es_palindromo("asa") -> True
es_palindromo("casa") -> False

Develop the function contar_ocurrencias that takes two parameters: frase and palabra, both of type string. The function should return the number of times that palabra occurs in frase.

Examples:
contar_ocurrencias("a ana y a mariana les gustan las manzanas", "ana") -> 3

You have attempted of activities on this page