+ 3

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

10th Nov 2020, 4:25 AM
Albert
Albert - avatar
38 Respostas
+ 85
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
10th Nov 2020, 5:26 AM
ChaoticDawg
ChaoticDawg - avatar
+ 15
If you don't want to use "join", here is an alternate solution using native loop. https://code.sololearn.com/c1CqwQVKc6U6/?ref=app
15th Dec 2020, 7:41 PM
Lam Wei Li
Lam Wei Li - avatar
+ 5
def concatenate(*args): word="" for i in range(len(args)): word=word+args[i]+"-" return word.strip("-") print(concatenate("I", "love", "Python", "!"))
17th Aug 2022, 7:54 AM
Rambabu Relli
+ 3
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!")) try this..
17th Aug 2022, 12:22 PM
K.M.B.M.Karunanayake
+ 1
Try this print("I-love-Python-!") xD
7th Nov 2022, 8:27 AM
Edin Mesic
Edin Mesic - avatar
0
i tried so many things and kept changing, this was my latest failed attempt
10th Nov 2020, 5:01 AM
Albert
Albert - avatar
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.
10th Nov 2020, 5:19 AM
ChaoticDawg
ChaoticDawg - avatar
0
I -_- D yes, donā€™t confuse with I of the print and I used in arguments, my bad
10th Nov 2020, 5:24 AM
Albert
Albert - avatar
0
ChaoticDawg understood! thanks!
10th Nov 2020, 5:29 AM
Albert
Albert - avatar
0
ASHISH YADAV it's print not Print
30th Apr 2021, 8:27 AM
TOLUENE
TOLUENE - avatar
0
def concatenate (*args): return '-'.join(args) Print(concatenate("I","love","python","!"))
29th May 2021, 3:48 AM
Sarika Phawade
Sarika Phawade - avatar
0
def concatenate(*args): return '-'.join(args)
1st Feb 2022, 2:16 PM
Avrian Shandy
Avrian Shandy - avatar
0
def concatenate(*args): result = None for i in args: if result == None: result = i else: result += "-" + i return result print(concatenate("I", "love", "Python", "!")) by janveer singh
17th Nov 2022, 5:07 AM
RAJVEER SINGH BAIRWA
RAJVEER SINGH BAIRWA - avatar
0
def func(*args): *a, b = args for i in a: print(i, end="-") return b
8th Feb 2023, 1:16 PM
JĆŗlia CiesarikovĆ”
JĆŗlia CiesarikovĆ” - avatar
0
I don't know
12th Aug 2024, 12:13 AM
Nathanael
- 1
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
16th Dec 2020, 6:33 PM
Abhijeet Rajwade
Abhijeet Rajwade - avatar
- 1
#Code is: def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
8th May 2021, 6:03 PM
LAKSHMI NARAYANAN M
LAKSHMI NARAYANAN M - avatar
- 1
def concatenate(*args): return "-".join(args)
19th May 2021, 12:31 PM
DanieL Gan
DanieL Gan - avatar
- 1
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
19th Nov 2021, 3:43 PM
Stefan Bartl
Stefan Bartl - avatar
- 1
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
31st May 2022, 11:00 AM
MATHEW Desmond Oyeyemi
MATHEW Desmond Oyeyemi - avatar