What is the highest number output by this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the highest number output by this code?

I get a bit confused with this code. What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) To what I understand, range(10) would be 1 to 9 and the highest number should be 9, why it is 0?

4th Oct 2017, 7:51 AM
hieu dotrong
hieu dotrong - avatar
16 Answers
+ 14
anything after the "return" won't run , so it will go through the loop one time and exit it out, not 9 times
4th Oct 2017, 8:55 AM
jay
+ 20
you have a return statement right after the print the loop only prints 0 then returns
4th Oct 2017, 8:00 AM
Burey
Burey - avatar
+ 7
I get a bit confused with this code. What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) To what I understand, range(10) would be 1 to 9 and the highest number should be 9, why it is 0? anything after the "return" won't run , so it will go through the loop one time and exit it out, not 9 times
28th Jun 2019, 8:26 PM
Samad Sunny
Samad Sunny - avatar
+ 5
That I understand return is as break there. If you remove "return" and run it will count from 0 to 9. If you add "break" instead of "return" the answer will be 0
4th Oct 2017, 8:01 AM
Ferhat Sevim
Ferhat Sevim - avatar
+ 3
0
19th Jan 2020, 8:49 AM
GOVINDHARAJPERUMAL R
GOVINDHARAJPERUMAL R - avatar
+ 1
0
11th Apr 2021, 10:22 AM
Md Imran Ahmad
Md Imran Ahmad - avatar
0
0
26th Oct 2018, 8:43 AM
Houcem Eddine Aouissaoui
Houcem Eddine Aouissaoui - avatar
0
it is o i did it
29th May 2019, 4:07 PM
Jawad Ahmad Qureshi
Jawad Ahmad Qureshi - avatar
0
0
23rd Feb 2020, 4:42 AM
VISHNUPRIYAN V
VISHNUPRIYAN V - avatar
0
✔ 0
21st Oct 2020, 5:48 PM
Md Maruf Billah
Md Maruf Billah - avatar
0
What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) Ana: 0
5th Dec 2020, 7:52 AM
IRFAN KHAN
IRFAN KHAN - avatar
0
What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) Ans: 0
12th Mar 2021, 6:44 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
0
def print_nums(x): for i in range(x): print(i) return print_nums(10) output: 0
22nd May 2021, 2:45 PM
Madhavareddy
Madhavareddy - avatar
0
What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) answer= 0
10th Jul 2021, 1:48 AM
Bimsara Senavirathna
Bimsara Senavirathna - avatar
0
0
6th Aug 2021, 5:05 PM
Tidjani Drichi Lool
Tidjani Drichi Lool - avatar
0
3
30th Aug 2021, 1:29 PM
J.Yuvaraj
J.Yuvaraj - avatar