This forum is now read-only. Please use our new forums! Go to forums
SyntaxError: 'return' outside function
This is my code: def fizz_count(x): count = 0 for item in x: if item == ‘fizz’: count = count + 1 return count
My indenting is fine, I think, even though the indenting doesn’t show here. The error is: File “python”, line 7 SyntaxError: ‘return’ outside function
Answer 53bf2a587c82caf33a0003a4
After you copy and paste your code into your post, you need to format it so we can see indentation, underscores, and other details. For instructions on formatting, see the link that looks like this:
Show formatting instructions ▼
Are you sure your indentation is correct? We cannot check it, because your code is not formatted, but your return
statement needs to be indented by exactly one level, in order for it to be properly situated in the fizz_count
function, without its being part of the for
loop or the if
block.
Here is the same code that you posted, but with correct indentation visible, so you can compare it to what you submitted to Codecademy’s Python interpreter:
def fizz_count(x):
count = 0
for item in x:
if item == 'fizz':
count = count + 1
return count
Each portion of the code is indented by one level to the right, with respect to its controlling header.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
THANK YOU SO MUCH!!! I appreciate it. :)