+ 1

Adding word

def concatenate(*args): my_list=[] for i in args: new_str= '-'.join(my_list) my_list.append(i) print(new_str) print(concatenate("I", "love", "Python", "!")) #This is my code for the adding word problem, but the output is “I-love-Python” and a “None” in next line,But the expected output is “I-love-Python-!”Can any one help me with this ?

28th Nov 2022, 4:52 AM
Pardis Shahabinejad
Pardis Shahabinejad - avatar
4 Réponses
+ 6
Pardis Shahabinejad , there may still be the issue that the final exclamation mark will not be printed. see my comments in the attached file. i also have made a suggsetion how the code can be simplified. https://code.sololearn.com/cukNV1Fv02qG/?ref=app
28th Nov 2022, 7:41 PM
Lothar
Lothar - avatar
+ 4
A function returns `None` when nothing was explicitly returned to the caller. That was why you see `None` in output. Solution: Modify concatenate() to return <new_str>
28th Nov 2022, 5:09 AM
Ipang
+ 2
Thanks a lot🙏🏼
28th Nov 2022, 5:24 AM
Pardis Shahabinejad
Pardis Shahabinejad - avatar
+ 1
Thanks for your help:)
28th Nov 2022, 7:57 PM
Pardis Shahabinejad
Pardis Shahabinejad - avatar