0

Why the outputs of this codes are 0 and the other rnd_int

Hello again, the module 3 quiz is breaking my head :C.... and I dont understand why the anwsers are like this What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) Why the answer is 0? ----------------------------------------------------------- How would you refer to the randint function if it was imported like this? from random import randint as rnd_int Why the answer is rnd_int? Im bad at this I know :S

24th Apr 2020, 9:22 PM
Guillermo GonzĂĄlez
2 Answers
0
Return stops the execution of function , that's why it runs once and only prints 0 , Answer is obviously rnd_int now ,you need to use rnd_int instead of randint ,if it was just from random import randint then you would have used randint but since you are importing it as rnd_int you will use that ,not sure what you don't understand about it!
25th Apr 2020, 9:30 AM
Abhay
Abhay - avatar
0
def print_nums(x): // 10 is passed for i in range(x): // for i in range 10 means 10 iterations with values 0,1,2,3....9 print(i) // i is 0 so it prints 0 return // this will return to from where it has been called. print_nums(10)
24th Apr 2020, 9:27 PM
Avinesh
Avinesh - avatar