+ 1
Why output is not same?
Plzz explain https://code.sololearn.com/ceGr6YJ4I83X/?ref=app https://code.sololearn.com/cbNI7mHZCYJb/?ref=app
5 ответов
+ 4
you write increasement
before if else statement in first code
In second code you write after if else
They work like
x=1
while x <= 13:
x+=1 # x is 2 now ,add 1 to initial value of x
if....
Second code
x=1
while x <= 13:
if x%2==0: #x is still 1
print(str(x) + " is even number")
else:
print(str(x) + " is odd number")
x+=1 #now x is 2 and loop till x=13
+ 2
KᗩᗩTᑌᗷᗩᗷᑌ
In first case you are first incrementing then checking condition so how could be result same?
+ 2
KᗩᗩTᑌᗷᗩᗷᑌ
In first case x will be 2 on 1st iteration.
In second case x will be remain same means 1 on 1st iteration. So obviously output would be different.
+ 2
Thanks , i understood now
+ 1
I did it by mistake , but i changed the code now.
Plzz check it.