Quiz - 7¶
Develop the function multi_cadena
that receives as parameters a string s
and a positive integer n
and returns a new string that contains n
copies of the original string
Examples:
multi_cadena("Hola", 2)
-> "HolaHola"
multi_cadena("Hola", 5)
-> "HolaHolaHolaHolaHola"
xxxxxxxxxx
def multi_cadena(s, n):
Activity: 1 ActiveCode (q7_1_en)
Develop the function expandir_cadena
that receives a string s
and returns a new string following the pattern described in the examples
Examples:
expandir_cadena("Code")
-> "CCoCodCode"
expandir_cadena("abc")
-> "aababc"
expandir_cadena("ab")
-> "aab"
def expandir_cadena(s):
Activity: 2 ActiveCode (q7_2_en)
Develop the function contar_apariciones_9
that receives as parameter a non-empty list of integers numeros
and returns how many times the number 9 appears in the list
Example: contar_apariciones_9([1, 99, 9])
-> 1
def contar_apariciones_9(numeros):
Activity: 3 ActiveCode (q7_3_en)
Develop the function verificar_comienzo_9
that receives a list of integer numbers numeros
and verifies if at least one of the first four numbers is a 9
Examples:
verificar_comienzo_9([1, 2, 9, 3, 4])
-> True
verificar_comienzo_9([1, 2, 3, 4, 9])
-> False
verificar_comienzo_9([1, 2, 3, 4, 5])
-> False
verificar_comienzo_9([1, 2, 9])
-> True
def verificar_comienzo_9(numeros):
Activity: 4 ActiveCode (q7_4_en)
Develop the function hola_usuario
that receives as a parameter a string nombre
that represents a user’s name and returns a greeting using this name
Examples:
hola_usuario("Bob")
-> "¡Hola Bob!"
hola_usuario("Alice")
-> "¡Hola Alice!"
hola_usuario("X")
-> "¡Hola X!"
def hola_usuario(nombre):
Activity: 5 ActiveCode (q7_5_en)
Develop the function crear_etiquetas
that receives two strings etiqueta
and palabra
and returns a new formatted string following the pattern of the examples
Examples:
crear_etiquetas("i", "Yay")
-> "<i>Yay</i>"
crear_etiquetas("i", "Hello")
-> "<i>Hello</i>"
crear_etiquetas("cite", "Yay")
-> "<cite>Yay</cite>"
def crear_etiquetas(etiqueta, palabra):
Activity: 6 ActiveCode (q7_6_en)
Develop the function repetir_letras
that receives a string s
of at least two characters and returns a new string with the last two letters repeated three times
Examples:
repetir_letras("Hello")
-> "lololo"
repetir_letras("abb")
-> "bbbbbb"
repetir_letras("Hi")
-> "HiHiHi"
def repetir_letras(s):
Activity: 7 ActiveCode (q7_7_en)
Develop the function otra_repetir_letras
(variation of the Exercise 7 function) that receives a string s
of at least two characters and a positive integer n
and returns a new string with the last two letters repeated n
times
Examples:
otra_repetir_letras("Hello", 3)
-> "lololo"
otra_repetir_letras("abb", 1)
-> "bb"
otra_repetir_letras("Hi", 5)
-> "HiHiHiHiHi"
def otra_repetir_letras(s, n):
Activity: 8 ActiveCode (q7_8_en)
Develop the function primera_mitad
that receives a string s
and returns the first half of the original string
Examples:
primera_mitad("WooHoo")
-> "Woo"
primera_mitad("HelloThere")
-> "Hello"
primera_mitad("abcdef")
-> "abc"
def primera_mitad(s):
Activity: 9 ActiveCode (q7_9_en)
Develop the function remove_first_last
that receives a string s
of at least two characters and returns a string without the first or last character.
Examples:
remove_first_last("Hello")
-> "ell"
remove_first_last("python")
-> "ytho"
remove_first_last("coding")
-> "odin"
def remove_first_last(s):
Activity: 10 ActiveCode (q7_10_en)
Develop the function rotate_left_2
that receives a string s
of at least two characters and returns the original string rotated 2 positions to the left.
Examples:
rotate_left_2("Hello")
-> "lloHe"
rotate_left_2("Hi")
-> "Hi"
def rotate_left_2(s):
Activity: 11 ActiveCode (q7_11_en)