Adding words code | Sololearn: Learn to code for FREE!

+4

Adding words code

You need to write a function that takes multiple words as its argument and returns a concatenated version of those words separated by dashes (-). The function should be able to take a varying number of words as the argument. Can anyone help with the solution

11/10/2020 4:25:59 AM

Albert

22 Answers

New Answer

+47

def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))

+7

If you don't want to use "join", here is an alternate solution using native loop. https://code.sololearn.com/c1CqwQVKc6U6/?ref=app

+2

This is how I did it as a beginner! def concatenate(*args): x = (args) print(x[0] + "-" + x[1] + "-" + x[2] + "-" + x[3]) concatenate("I", "love", "Python", "!")

+1

i tried so many things and kept changing, this was my latest failed attempt

+1

ChaoticDawg understood! thanks!

+1

#Code is: def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))

0

You're close. 1. Remove l and just use *args as the parameter and arg as the argument for join. 2. Instead of s = just return the result of join() from the function 3. print() the returned value from the call to your function.

0

I -_- D yes, don’t confuse with I of the print and I used in arguments, my bad

0

Print ("I love python") Is it correct? Because I m getting wrong many times

0

ASHISH YADAV it's print not Print

0

def concatenate(*args): return "-".join(args)

0

def concatenate (*args): return '-'.join(args) Print(concatenate("I","love","python","!"))

-1

def concatenate(l, *args): s = '-'.join(l) (concatenate("I", "love", "Python", "!"))

-1

def fun(lst): return "-".join(lst) is this what you meant?

-1

ChaoticDawg can you explain the 3rd point please

-1

def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))

-1

You need to write a function that takes multiple words as its argument and returns a concatenated version of those words separated by dashes (-). The function should be able to take a varying number of words as the argument. Sample Input this is great def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))

-1

def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))

-1

def concatenate(*args): x = (args) print(x[0] + "-" + x[1] + "-" + x[2] + "-" + x[3]) concatenate("I", "love", "Python", "!")

-1

Your article content is very interesting. I am very impressed with your post. I hope to receive more great posts. https://www.omegle.vin/