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?

30th Dec 2022, 9:13 PM
Bilge Tandogan
Bilge Tandogan - avatar
4 odpowiedzi
+ 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
31st Dec 2022, 6:00 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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.
30th Dec 2022, 9:21 PM
Lothar
Lothar - avatar
+ 4
X = 0, because at the first iteration i = 0, multiple by 0 is 0
31st Dec 2022, 3:03 PM
GerlahVeniamin
+ 1
Lothar , i understand, thanks
30th Dec 2022, 9:31 PM
Bilge Tandogan
Bilge Tandogan - avatar