Why is the print order reversed?

Blockquote

def about_this_computer():
print(“This computer is running on version Everest Puma”)
print(“This is your desktop”)

about_this_computer()

When Used This Pieces Of Code Why The Second Print Function Came First As A Result
As

This is your desktop
This computer is running on version Everest Puma

6 Likes

def about_this_computer():
print(“This computer is running on Whackintosh version Everest Puma”)
print(“This is your desktop”)

about_this_computer()

Why The Second PRINT FUNCTION CAME FIRT AS A RESULT ???

Likely because it is not indented so is part of the global namespace and runs immediately. Notice it is positioned before the function call?

def foo():
    print ('foo')

print ('bar')

foo()

Output

bar
foo
5 Likes

Then what’s the solution of this as our intention is to unindent the last line so that the last print function could not be executed.

This is happening with me as well. It doesn’t make sense from what the text expects and what the output is.

The text specifically says

" When we call greet_customer , the message "Cleanup on Aisle 6" is not printed, as it is not part of the function."

If we run

def greet_customer():
print(“Welcome to Engrossing Grocers.”)
print(“Our special is mandarin oranges.”)
print(“Have fun shopping!”)
print(“Cleanup on Aisle 6”)

greet_customer()

The the output is

Cleanup on Aisle 6
Welcome to Engrossing Grocers.
Our special is mandarin oranges.
Have fun shopping!

That directly contradicts what the text says with the instructions:

  1. Run script.py . Look at what is printed out!

  2. Remove the indent on the second print statement. Run the file. Now what’s printed?

It needs clarification because it’s not correct. The code and output might be correct (I have no idea I’m learning) but the text instructions are not.

It should state Notice Cleanup on Aisle 6 is printed first and not part of the function… or something along those lines.

Could somebody please post a link to this exercise? Thank you.

1 Like

https://www.codecademy.com/courses/learn-python-3/lessons/intro-to-functions/exercises/whitespace

1 Like

This instruction issue has been reported to the curriculum team.

1 Like

" When we call greet_customer , the message "Cleanup on Aisle 6" is not printed, as it is not part of the function."

Although I agree that "Cleanup on Aisle 6" shouldn’t have been printed, I think the point they were trying to make here is that any other code not written after 2 indentations (or whatever indentation the function defines) will not be part of the function.

If we use the same function anywhere else, only

print(“Welcome to Engrossing Grocers.”)
print(“Our special is mandarin oranges.”)
print(“Have fun shopping!”)

will be printed, and won’t include print(“Cleanup on Aisle 6”).

In the example, because the latter was written after the function, the output will, as a result, print it, as well. But, again, what bothers me is “Remove the indent on the second print statement. Run the file. Now what’s printed?”