+ 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
38 Respostas
+ 85
def concatenate(*args):
return '-'.join(args)
print(concatenate("I", "love", "Python", "!"))
+ 15
If you don't want to use "join", here is an alternate solution using native loop.
https://code.sololearn.com/c1CqwQVKc6U6/?ref=app
+ 5
def concatenate(*args):
word=""
for i in range(len(args)):
word=word+args[i]+"-"
return word.strip("-")
print(concatenate("I", "love", "Python", "!"))
+ 3
def concatenate(*args):
return '-'.join(args)
print(concatenate("I", "love", "Python", "!"))
try this..
+ 1
Try this
print("I-love-Python-!")
xD
0
i tried so many things and kept changing, this was my latest failed attempt
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.
0
I -_- D yes, donāt confuse with I of the print and I used in arguments, my bad
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)
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
0
def func(*args):
*a, b = args
for i in a:
print(i, end="-")
return b
0
I don't know
- 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
def concatenate(*args):
return '-'.join(args)
print(concatenate("I", "love", "Python", "!"))