+ 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 ?
4 odpowiedzi
+ 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
+ 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>
+ 2
Thanks a lot🙏🏼
+ 1
Thanks for your help:)