[SOLVED] Unexpected None value in solution. Adding Words problem attempt. | Sololearn: Learn to code for FREE!


[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?

11/16/2020 4:22:40 AM


8 Answers

New Answer


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 "-"? 😁


If you don't want to use "join", here is an alternate solution using native loop. https://code.sololearn.com/c1CqwQVKc6U6/?ref=app


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.


A similar question for this same problem was asked just a few days ago. https://www.sololearn.com/Discuss/2583975/?ref=app


1 - def name(*args): 2 - x = "-".join(args) 3 - print (x) 4 - 5 - name('I','love','Python','!')


def concatenate(*args): return '-'.join(args) print(concatenate("I", "love", "Python", "!"))


Cool, thanks i'll have a look


What an easy 100 XP! print("I-love-Python-!") 🤣