FAQ: Code Challenge: Loops - Greetings


#1

This community-built FAQ covers the “Greetings” exercise from the lesson “Code Challenge: Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

FAQs on the exercise Greetings

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

I genuinely don’t know why this is wrong. May I get some help? I don’t want them to just give me the answer; I want my logic to be adjusted.

def add_greetings(names):
  for i in names:
    names.append('Hello, ' + i)

EDIT: So I figured out that I’m causing an infinite loop. but now my code looks like this:

def add_greetings(names):
  greeting = ["Hello, " + i for i in names]
  names.append(greeting)

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

But my output is “None”


#3

Why doesn’t this work? I mean technically it does, but without providing a return statement I have to deal with “None” showing up at the right

When I try to write the code with “return” instead of “print” I get only “Hello, Owen”. Why doesn’t it loop through all of the names?

This is literally just me trying to figure out alternate paths to the same solution–I’ve already completed the assignment the way it asked. Thank you for your help!


#4

I can’t fix your logic because I’m at the same level as you, but I was told in a previous post I made that “none” shows up because the program CodeAcademy uses expects some kind of return statement within the functions you create.

This was for a different project, but I also had “None” show up in this project and adding return worked. Maybe try “return names.append(greeting)”


#5

I had the same error, figured out that the indentation in return function was the cause.