+ 1

What's wrong in this code ?

>>> x = 50 >>> y = 80 >>> while x<50 and y<100 : x = x + 1 y = y + 1 print(x , y) -------------------------- The codeplayground show error so what't wrong with this code ?

28th Mar 2017, 9:10 AM
Tushar
Tushar - avatar
2 Answers
+ 13
Remove >>> and it should be or not and.
28th Mar 2017, 9:14 AM
Dev
Dev - avatar
0
Hi, when I'm running the code, I don't get an error, I just get 'no output'. That is because you are checking if x is less than 50 AND y less than 100. For an AND to work, both sides have to be true. If this is not the case, you will never get into the while loop. You could use an OR statement, which will execute your code until y = 100 (x is already 50). Or you could use while x <= 50 and y <= 100, which will execute the loop only once (after that, x = 51 and one of the sides will be false). Hope this helps :)
28th Mar 2017, 9:28 AM
Nox
Nox - avatar