0

Returning from Functions

Hi guys, I think i have a easy question but it maybe not, how do you explain this: What is the highest number this function prints if called? def print_numbers(): print(1) print(2) return print(4) print(6) the result to this problem is 2 or that's what the system says, however i type the code as you see it here and it comes back to me as 4, 6. there for the highest number is 6 and not 2. anyone would you like to take on this one please. Thank you.

4th Jan 2018, 6:56 PM
ruben
ruben - avatar
5 odpowiedzi
+ 8
Take note that Python use indentation as statement separator instead of the traditional semicolon. Therefore you'll get different result with different level of indentation. Try to play with it and you'll find it out. 😉 https://code.sololearn.com/c7w7SYbzQTNf/?ref=app
5th Jan 2018, 3:24 AM
Zephyr Koo
Zephyr Koo - avatar
+ 6
If you see 4, then print(4) probably isn't in the scope of the function.
4th Jan 2018, 7:41 PM
Eric Blinkidu
Eric Blinkidu - avatar
+ 1
I ran the code and I got 12 print(1) and print (2) are on the same line making it look like the number 12 so I think the answer is 12 sorry I ran this code in Ruby not Python...
4th Jan 2018, 8:45 PM
Dick Tracy
Dick Tracy - avatar
+ 1
answer is 2
12th May 2019, 7:00 AM
KIRUTHIKA S
KIRUTHIKA S - avatar
- 1
howdy guys, first of all Big Thank you to all for your help, but i code it again and still the answer is 6, the way the code falls as you type it by the python default page is like follows: def print_numbers(): print(1) print(2) return print(4) print(6) and the result of this code is 4, 6 there for the highest number is 6 and no 2 as the multi-answer page suggest me. Now if you type it as i put it before,: def print_numbers(): print(1) print(2) return print(4) print(6) Then the result of this code is nothing, yeah! i know, mad isn't, but the answer to this code type just as you see it here is: ============= RESTART: C:\Users\user\Desktop\python\practices.py ============= >>> and that's all what it is, so as you can see guys this still confusing to me, one more time i have the feeling of losing points no been by my own errors. once again guys thank you all for looking into my coding troubles if someone can put some more light on this i will be very grateful. Thank you.
5th Jan 2018, 1:42 PM
ruben
ruben - avatar