Python Functions Quiz - What happens when you call report?


#1

First of all - the course and website are great; I love it!
So, I’m currently doing the Python Function quiz section of the Data Science path.

https://www.codecademy.com/paths/data-science/tracks/dspath-functions-and-logic/modules/dspath-python-functions/quizzes/functions-quiz

In the Python Functions quiz we’re asked:
What happens when you call report?

time = "3pm"
mood = "good"

def report():
  print("The current time is " + time)
  print("The mood is " + mood)

print("End of report")

The “correct” answer is given as:
Two Strings are printed: "The current time is 3pm" and "The mood is good"
And the tooltip says: " Only the first two print statements are inside the report function."

However, if we call report() and add it over or under print(“End of report”), said print() is still being printed, and the result is:
The current time is 3pm
The mood is good
End of report

This is a case where print() is on the scope of the ENTIRE script, thus - it is always printed.
I also tried this on some python interpreter, which gave me the above string.

So…am I missing something here? Or is the answer incorrect?
Thanks!


#2

Admittedly, the question is a bit vague. Evidently, the authors of the quiz would like the user to identify only the output that is a direct result of calling the report function, and not any other output that gets displayed as a result of additional lines of code outside the function. The question should be reworded to make that clear.


#3

That was my first thought, thanks :slight_smile:
I’d like to elaborate as someone who read the question as a user for the first time. The code is:

time = "3pm"
mood = "good"

def report():
  print("The current time is " + time)
  print("The mood is " + mood)

print("End of report")

And the quiz asks what happens when we call report() with the global variables “time” and “mood”, but in the same time it ignores the current “global statement” print(“End of report”) .

To me, that’s odd - either you use just write the def report(): block so the user doesn’t get confused (and in which case the current correct answer would make more sense), or don’t ignore other variables and print() statements.

Thanks for the input Glenn, hopefully this will be reworded!