+ 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?
16 Respuestas
+ 14
anything after the "return" won't run , so it will go through the loop one time and exit it out, not 9 times
+ 20
you have a return statement right after the print
the loop only prints 0 then returns
+ 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
+ 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
+ 3
0
+ 1
0
0
0
0
it is o i did it
0
0
0
✔ 0
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
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
0
def print_nums(x):
for i in range(x):
print(i)
return
print_nums(10)
output: 0
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
0
0
0
3