0

Comparison between tow blocks

x =10 while x>0 : if x%2 ==0 : print (str(x) + "is even") else : print ( str(x) + "is odd" ) x -= 1 .... x = 1 while x < 10: if x%2 == 0: print(str(x) + " is even") else: print(str(x) + " is odd") x += 1 . What is the difference between these blocks ??

19th May 2023, 1:45 AM
Majd Mohammad Hussein
Majd Mohammad Hussein - avatar
6 ответов
+ 9
Plus, the second block works, but the first one doesn't. Double check its indentation.
19th May 2023, 3:57 AM
Emerson Prado
Emerson Prado - avatar
+ 8
Majd Mohammed Hussein , for better readability of the source code, we should apply the python style guides: > https://peps.python.org/pep-0008/#indentation
19th May 2023, 4:49 PM
Lothar
Lothar - avatar
+ 6
Learn comparison operators from python course, you will know that behind the logic in that program
19th May 2023, 3:33 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Decreasing and increasing steps
19th May 2023, 1:58 AM
Mbengue Mbor
Mbengue Mbor - avatar
+ 2
Majd Mohammed Hussein This will result in an infinte loop, since you decrement x outside the loop
19th May 2023, 11:41 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Majd Mohammed Hussein one code prints numbers in ascending order, the other prints in descenting. Have you tried running these codes? If you do you'll immediately see the difference, once you fix all the errors in the first code.
20th May 2023, 10:34 PM
Евгений
Евгений - avatar