0

Why is output 11?

x = 0 c = 0 while x<=20 : x =x+2 c = c+1 print(c)

8th Jan 2023, 4:42 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar
9 Réponses
+ 9
x = 0 and increase 2 atime while C is 0 and increase 1 a time x will keep 10 times(*2) then it will be 20 and the loop will make it increase once again because it is equal to 20 so the c will get more more and will be 11 x = 22 greater than 20 so the loop stops while c is now 11
8th Jan 2023, 4:49 PM
Ali M
Ali M - avatar
+ 8
🌻Emàâââ🌻 , please do not post duplicated questions.
8th Jan 2023, 4:47 PM
Lothar
Lothar - avatar
+ 1
I saw this in my teacher's old exam and i don't know why is the answer is 11 so i asked for help
8th Jan 2023, 4:50 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar
+ 1
Lothar yeah, i was like what the heck i just answered that question, i hope the answer wasn't just removed hehehe
8th Jan 2023, 4:50 PM
Ali M
Ali M - avatar
+ 1
🌻Emàâââ🌻 simple answer, the loop will work 11 times until x become not equal and not smaller than 20 and the c will become 11 because the loop worked 11 times
8th Jan 2023, 4:52 PM
Ali M
Ali M - avatar
+ 1
x = 0, 2, 4, 6, 8, 10, 12, 14 , 16, 18, 20 This are the 11 conditions for which loop will run that's why the value of c will be incremented 11 times and answer will be 11 👍
9th Jan 2023, 4:49 PM
Lokesh Soni
Lokesh Soni - avatar
+ 1
Because it's less than and equal to
9th Jan 2023, 4:54 PM
Sanjay Kamath
Sanjay Kamath - avatar
0
Thank u so much 🙏🏻
8th Jan 2023, 4:53 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar
0
Maybe you saw my post because i posted it two time
8th Jan 2023, 5:09 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar