+ 2
Why this code is giving output 2even if the function is not called ????
def print_numbers() print(1) print(2) return print(3)
6 Respostas
+ 2
check it now
+ 2
In addition to indentation, there's no trailing colon (:) on the function definition.
+ 2
the same code was given in the functions section as question and the answer was 2 ... how????
+ 2
Hey...those details are important. It can be frustrating getting them all but it really helps (us and you).
I went to the "functions section" but it wasn't there (others might have looked too, not found it and left). I found it as the last question in a later block: "Returning from Functions".
The function above isn't the same...well, almost...but distracting because it's not indented properly (a plausible reason for returning 2 + crash) possibly also if the missing : is a typo.
You indicate "even if the function is not called" when the question is:
"What is the highest number this function prints if called?"
It's 2 in the question because when you imagine the function is called, the return statement ends the indented block, and the next two lines (where you show 1) are ignored.
If you have a copy of the code like the above, it's 2 for you probably because the 'return' statement stops the interpreter...but not before it prints, assuming a typo at 'def' or something...when it 'falls through' the code without indent hints.
I'm sure about the first reason, not so sure about the second.
+ 1
Did you forget to indent the code?
0
where is the code