- 1

Adding word

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 Sample Output this-is-great How to solve I was try more than 15 times :(

21st Oct 2020, 5:06 PM
Pritee
10 Respostas
21st Oct 2020, 5:09 PM
Ananiya Jemberu
Ananiya Jemberu - avatar
+ 4
If you are having difficulty then check out this.. I have tried to explain everything in here.. Do the changes you want. https://code.sololearn.com/ckKvB8v8Gf0K/?ref=app
22nd Oct 2020, 2:51 AM
Akshaya Narayana Bhat
Akshaya Narayana Bhat - avatar
+ 2
def add(*words): return '-'.join(words) print(add('w0', 'w1', 'w2'))
21st Oct 2020, 5:24 PM
QTWizard
+ 2
def concatenate(*args): result = None for i in args: if result == None: result = i else: result += "-" + i return result print(concatenate("I", "love", "Python", "!"))
22nd Jun 2021, 3:45 AM
Paras kafle
Paras kafle - avatar
+ 1
Where is your attempt show us Use .join method to join them after appending them to a list
21st Oct 2020, 5:10 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Thanks 😊
21st Oct 2020, 5:30 PM
Pritee
0
def concfunc(*conc_words): return '-'.join(conc_words) print (conc_words) print(concfunc("I", "love", "Python","!"))
11th Mar 2021, 9:34 AM
Lifezrockin
0
print ("Enter words for concatenating separated by space") input_words = input() word_list = input_words.split() joined_words = "-".join(word_list) print (joined_words)
16th Mar 2021, 6:34 AM
Lifezrockin
0
def concatenate(*args): con = "" for i,arg in enumerate(args): if i<len(arg): con += arg + "-" else: con += arg return con print(concatenate("I", "love", "Python", "!"))
25th May 2022, 10:23 PM
Paul Gwambe
Paul Gwambe - avatar
- 1
def concatenate(*args): x = (args) print(x[0] + "-" + x[1] + "-" + x[2] + "-" + x[3]) concatenate("I", "love", "Python", "!")
22nd Jun 2021, 3:44 AM
Paras kafle
Paras kafle - avatar