Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to update a variable
#4
The indentation controls that. As line 7 goes back to the previous level of indentation, it marks itself as outside the previous scope.

You're only using one space for your indentation. While legal, it makes it much harder to see which statement is at what level. The recommendation is to use four spaces, which makes the statement levels more easily visible.

second = 1
third = 1
 
while second < 100:
    while third < 50:
        print(third)
    third += 1
print(second)
second += 1
Lines 8 and 9 are outside all loops and would only be executed if the loop were ended (which it will not with the current code).
Reply


Messages In This Thread
how to update a variable - by astral_travel - Apr-06-2020, 08:06 AM
RE: how to update a variable - by bowlofred - Apr-06-2020, 08:46 AM
RE: how to update a variable - by astral_travel - Apr-06-2020, 08:53 AM
RE: how to update a variable - by bowlofred - Apr-06-2020, 09:23 AM
RE: how to update a variable - by astral_travel - Apr-06-2020, 03:54 PM
RE: how to update a variable - by Newerpython - Apr-06-2020, 04:22 PM
RE: how to update a variable - by astral_travel - Apr-06-2020, 05:26 PM
RE: how to update a variable - by snippsat - Apr-06-2020, 05:56 PM
RE: how to update a variable - by astral_travel - Apr-06-2020, 07:33 PM
RE: how to update a variable - by snippsat - Apr-06-2020, 07:46 PM
RE: how to update a variable - by astral_travel - Apr-06-2020, 08:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 4,006 Dec-16-2020, 05:26 AM
Last Post: Vokofe

Forum Jump:

User Panel Messages

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