- 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 :(
10 odpowiedzi
+ 7
Pritee please don't post 🙅 a challenge in new thread perhaps, there is many thread to do it tho
https://www.sololearn.com/discuss/475577/?ref=app
https://www.sololearn.com/discuss/497411/?ref=app
https://www.sololearn.com/discuss/1701380/?ref=app
https://www.sololearn.com/discuss/1482337/?ref=app
+ 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
+ 2
def add(*words):
return '-'.join(words)
print(add('w0', 'w1', 'w2'))
+ 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", "!"))
+ 1
Where is your attempt show us
Use .join method to join them after appending them to a list
+ 1
Thanks 😊
0
def concfunc(*conc_words):
return '-'.join(conc_words)
print (conc_words)
print(concfunc("I", "love", "Python","!"))
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)
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", "!"))
- 1
def concatenate(*args):
x = (args)
print(x[0] + "-" + x[1] + "-" + x[2] + "-" + x[3])
concatenate("I", "love", "Python", "!")