+ 2

Can any explain this pls

X = 0 Z = [1,2,3,4,5] For I in z : X = x + I If not (x<9): Result = x - I Print(result) Break

24th Sep 2022, 7:41 PM
ZIZO Abd alkawy
6 Antworten
+ 3
Solo , we can not just take a single test case and assume that everything will be correct. this is careless. if the list has other values, it matters. e.g. [1,2,3,1,1,1,1]
25th Sep 2022, 11:18 AM
Lothar
Lothar - avatar
+ 2
The sum of the values ​​of z is assigned to x until it becomes greater than 9, then the condition will work and subtract the last value from x, print the result and stop the loop. 0+1+2+3+4 < 9 —> false not false —> true result = 10 - 4
24th Sep 2022, 8:49 PM
Solo
Solo - avatar
+ 2
Solo , shouldn't it be: "the sum of the values of z is assigned to x until it becomes *GREATER OR EQUAL* than 9..."
25th Sep 2022, 6:49 AM
Lothar
Lothar - avatar
+ 1
Lothar , yes but in this case x will never be equal to 9 😎
25th Sep 2022, 7:00 AM
Solo
Solo - avatar
+ 1
Lothar , no buddy, we are looking at a specific example, not some abstract statements.
25th Sep 2022, 11:32 AM
Solo
Solo - avatar
0
Recheck your code there is lot of error like capital letter s "F" for ,for loop and variable. correct this small error.
25th Sep 2022, 5:59 PM
KARAN SINGH D
KARAN SINGH D - avatar