Ayuda ultimo ejercicio Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ayuda ultimo ejercicio Python

Este dice el ejercicio: Necesitas escribir una función que tome múltiples palabras como argumento y devuelva una versión concatenada de esas palabras separadas por guiones (-). La función debe ser capaz de tomar un número variable de palabras como argumento. Ejemplo de entrada this is great Ejemplo de salida this-is-great Me puede ayudar con esta respuesta por favor?

7th Jul 2022, 4:11 AM
Harol Steven
Harol Steven - avatar
4 Answers
+ 2
The exercise wants you to practice how *args work. The function signature should look like this: def concatenate(*args): Then args will become a tuple that contains all the words passed to the function. You can choose different strategies to build the result. You can start with an empty string, loop through the args and add each word and a separator. But a much cleaner way is to use the join() method of the string. Review the Lesson 59.1 in Python Core (Useful functions) and hopefully you'll figure out the solution. Experiment with join in the code playground!
7th Jul 2022, 4:44 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Good Tabor, we did it. Thank you
7th Jul 2022, 5:29 AM
Harol Steven
Harol Steven - avatar
0
Estes es el codigo que tengo: def concatenate(x,*args): print (x+"-"+str(args)) concatenate("I", "love", "Python", "!") Pero no me funciona
7th Jul 2022, 4:13 AM
Harol Steven
Harol Steven - avatar
0
Thank you for your support Tibor. I’m going to try and i will let you know.
7th Jul 2022, 5:10 AM
Harol Steven
Harol Steven - avatar