Code clarification

def add_greetings(names):

 for name in names:

   count = 0
   print("Hello, " + name)
   count += 1

print(add_greetings(["Owen", "Max", "Sophie"])

Output: Hello Owen
Hello Max
Hello Sophie
None
What’s Wrong with my code, Why none occurs despite of count definition?

A function that completes its execution without output e.g. no return will always return None. Why might this be printed?

4 Likes

I found this error. Despite adding the return statement “return names” code is appearing with a different Output: Hello Owen,
Owen

What did you want to print? Does your code reflect that? It won’t be printing an output unless you asked for one.

1 Like

The output must be printed like this: Hello Owen
Hello Max
Hello Sophie
Within a List

What seciton of your code is responsible for printing each of these lines? Is it the same part, or more than one?