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

13 Answers

New Answer

+21

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

+2

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.

+2

ChaoticDawg understood! thanks!

+2

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

+1

Show us your attempt

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

0

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

0

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

0

ChaoticDawg can you explain the 3rd point please

-1

def concatenate(l, *args): s = '-'.join(l) (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", "!"))