Why the conditional operator is not giving the expected result (in Python)? -
for given python code, can help me find why not getting expected result?
i=1 j="hello" k="world" while i<101: if i%15==0: # answers, if forgot remove print j+k if i%15==0 else j if i%3==0 else k if i%5==0 else i+=1
my expectation:
1 2 hello 4 world hello 7 . 14 helloworld . .
but result is:
helloworld helloworld helloworld helloworld helloworld
if i%15==0: print j+k if i%15==0 else j if i%3==0 else k if i%5==0 else
the sec line execute when i%15 == 0
, first status on print true. is, every time sec line executed, i%15 == 0
, since have j+k if i%15==0
print j+k
.
if remove line if i%15==0:
should result expecting.
python
No comments:
Post a Comment