0

[SOLVED] Unexpected None value in solution. Adding Words problem attempt.

I was attempting to solve the Adding Words project for python and wrote the below code: def concatenate(*words): """Takes a string of words and concatenates them together with a '-' separating the words""" for word in words: print(word, end='-') print(concatenate("I", "love", "Python", "!")) Whenever I run this code python is adding a None value to the string i.e. I-love-Python-!-None Can someone explain why the None value is being added to the end of the string?

16th Nov 2020, 4:22 AM
Garrett
10 odpowiedzi
+ 8
Since your function contains a print function, you don't need to print it. Just call it, i.e. concatenate("I", "love", "Python", "!") You get None when you try to print a print. How are you going to get rid of the final "-"? 😁
16th Nov 2020, 4:29 AM
David Ashton
David Ashton - avatar
+ 5
If you don't want to use "join", here is an alternate solution using native loop. https://code.sololearn.com/c1CqwQVKc6U6/?ref=app
15th Dec 2020, 7:42 PM
Lam Wei Li
Lam Wei Li - avatar
+ 2
Oh ok that makes sense. Thanks David Ashton. I'll have to go back and change my code, cause it looks like I have more problems than just the None value.
16th Nov 2020, 6:07 AM
Garrett
+ 1
A similar question for this same problem was asked just a few days ago. https://www.sololearn.com/Discuss/2583975/?ref=app
16th Nov 2020, 5:44 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
1 - def name(*args): 2 - x = "-".join(args) 3 - print (x) 4 - 5 - name('I','love','Python','!')
19th Nov 2020, 8:01 PM
Sam Jack
Sam Jack - avatar
0
Cool, thanks i'll have a look
18th Dec 2020, 3:09 PM
Sam Jack
Sam Jack - avatar
0
def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))
19th Nov 2021, 3:43 PM
Stefan Bartl
Stefan Bartl - avatar
0
Really? It was that easy!? I was close anyway 😏 Thanks for the help guys, certificate here I come
30th Aug 2022, 7:10 PM
A Phil
A Phil - avatar
- 1
What an easy 100 XP! print("I-love-Python-!") 🤣
5th Feb 2021, 4:39 AM
David Ashton
David Ashton - avatar
- 1
def concatenate(*args, sep="-"): return sep.join(args) Print(concatenate ("i", "love", "python" ,"!"))
7th Sep 2022, 11:31 AM
Helitha Rupasinghe
Helitha Rupasinghe - avatar