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 ??
6 ответов
+ 9
Plus, the second block works, but the first one doesn't. Double check its indentation.
+ 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
+ 6
Learn comparison operators from python course, you will know that behind the logic in that program
+ 2
Decreasing and increasing steps
+ 2
Majd Mohammed Hussein This will result in an infinte loop, since you decrement x outside the loop
+ 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.