0
What is the output of this code? num = [1, 2, 3, 4] x = 1 for i in range(0, len(num)): x *= i print(x) by #RahulVerma
Is there anyone who can help?
4 Réponses
+ 5
Bilge Tandogan
That is a trick question from the challenges.
The answer is 0
The reason being that x is being multiplied by a range of numbers starting from 0. len(num)==4
1 *= 0 -> 0
0 *= 1 -> 0
0 *= 2 -> 0
0 *= 3 -> 0
x = 0
+ 5
Bilge Tandogan ,
the code as it is has an issue in the for loop:
x *= i has to be indented.
now you can try to run the code and see the result.
+ 4
X = 0, because at the first iteration i = 0, multiple by 0 is 0
+ 1
Lothar ,
i understand, thanks