0

What happens when I insert 0 in the following code? Especially range becomes range (2,1)

https://code.sololearn.com/c4TIvLVl65Y8/?ref=app

22nd Dec 2019, 3:50 PM
Baran Aldemir
Baran Aldemir - avatar
6 Antworten
+ 3
Baran Aldemir fac will remain the same, so the output will be the initial value fac had, which is 1. The for loop breaks immediatly, but the while loop will not break.
22nd Dec 2019, 4:16 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Baran Aldemir it doesn't assign anything, because there are no values in that range
22nd Dec 2019, 3:56 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Replace "number" with 0 and try this: print(list(range(2,1)) result is [] So your "for" loop can be written as "for i in []": it is never entered; it is skipped. "fac" variable, as Aymane Boukrouh [Unavailable] pointed out, will not be changed and its value will remain equal to 1
22nd Dec 2019, 6:22 PM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
Nothing, it will just consider it as an empty list
22nd Dec 2019, 3:51 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
What does it assign to i then? 0? 1? None?
22nd Dec 2019, 3:55 PM
Baran Aldemir
Baran Aldemir - avatar
0
What happens then? Returns the initial fac and breaks the for loop?
22nd Dec 2019, 4:13 PM
Baran Aldemir
Baran Aldemir - avatar