Introduction to Functions - Whitespace & Execution Flow, can't continue lesson

Direct link to lesson.

Hi,

I am currently working my way through the Data Analyst Career Path and found myself a little stumped on section 5/13 , task 3;

  1. Oh no! It looks like some clouds came in and it started raining. Our users shouldn’t go on a trip in the rain. In our weather_check() function add a second print() statement under the first one which prints a warning message for our travelers! It should print:

False Alarm, the weather changed! There is a thunderstorm approaching. Cancel your plans and stay inside.

Please find below the code I have written for this lesson;

# Your code below: 
print("Checking the weather for you!")

def weather_check():
  print("Looks great outside! Enjoy your trip.") 
  print("False Alarm, the weather changed! There is a thunderstorm approaching. Cancel  your plans and stay inside.")

weather_check()

I have defined the function which has two print statements inside of it, indented. When calling the function I receive the desired output. However, the lesson does not let me click next. When looking at the solution, this is the code;

 # Write your code below!
 print("Checking the weather for you!")  
 
 def weather_check():
   print("Looks great outside! Enjoy your trip.")
print("False Alarm, the weather changed! There is a thunderstorm approaching. Cancel your plans and stay inside.")

weather_check()

The second print statement is not indented and thus not inside the function despite the lesson asking to include the second print statement inside the function. Is this an error in the lesson or am I having a moment and reading this incorrectly?

When using the solution that is offered and commenting the called function, the first print statement and the third are output. Which is what I would expect with the solution code. With my code, the first print statement outputs if the function is not called. If called, all 3 statements are output, which I thought was what the lesson was attempting to showcase.

Thanks.

There’s a couple of things that aren’t clear when going through the courses.

  1. When you click ‘view solution’, it gives you the code that’s correct at the end of the exercise. (and in your case the last bit is asking you to unindent that line, which is why it looks wrong at the point you’re at.)

  2. It can be fussy about the text in the strings. (for instance, it looks like you have an extra space between Cancel and your.) If in doubt copy and paste what they’re asking

I tried removing the extra space, but was still encountering the error.

I was also receiving a message at the bottom of the coding panel in red asking if I had placed the print statement inside the function. This is what was causing the error and not allowing me to continue the lesson, even though the print statement was inside the function.

I didn’t know the solution shows the final code, however. Thanks for that. I copied the solution and it let me pass that section of the lesson, which again, is confusing because as you said the next step of the lesson is to un-indent the print statement to remove it from the function. Either the wording, the task or the error don’t make sense here.

Occasionally it’ll seem uncooperative, and overly fussy. If it looks like I’ve done it right and I can’t see an obvious error, sometimes I’ll just clear it and try again.
I know I kept tripping myself up confusing 1 and l (little L), and still can’t help putting u’s in colour.

On the brightside, at least it means you’re thoroughly checking your work…

Yeah, I have a background in I.T but have struggled to learn coding previously. The way the Codecademy syllabus is set up seems to make it a little easier for my brain to understand what are the important basics of Python 3. I like to check over my work and see if I am going wrong somewhere - which is usually the case :sweat_smile:.

1 Like