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

0

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

29 Answers

New Answer

+62

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

+11

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

+1

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", "!")

0

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

0

ChaoticDawg understood! thanks!

0

ASHISH YADAV it's print not Print

0

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

0

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

-1

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.

-1

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

-1

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

-1

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

-1

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

-1

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

-1

print("I-love-Python-!") Haha lol

-1

I like reading different ways people solve problems. I didn't even think to use join. My approach was as follows def concatenate(x,*args): for i in args: x=x+"-"+i return (x) print(concatenate("I", "love", "Python", "!"))

-2

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

-2

ChaoticDawg can you explain the 3rd point please

-2

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", "!"))

-2

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