Python Forum
Different Indentation Different Result
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different Indentation Different Result
#1
sump=0
for num in listp:
    if num%2==0:
        sump=sump+num
        print(sump
sump=0
for num in listp:
    if num%2==0:
        sump=sump+num
    print(sump)
sump=0
for num in listp:
    if num%2==0:
        sump=sump+num
print(sump)
Here are technically the same code, but as I play around with the indentation of print(sump) Im having differente results.

Could someone explain to me why is it about the indentation of print that makes the result different every time?
Reply


Messages In This Thread
Different Indentation Different Result - by el_bueno - Feb-11-2020, 09:01 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020