Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loop within loop confusion
#1
I'm trying out nested loops. I included the error message I get at the end. I simply cannot see how indentation is inconsistent. Please help

#Program loops
start_for = 3
end_for = 102

for c in range(start_for, end_for,2):
    for x in range(3,10,2):
        remainder=c%x
        if remainder > 0:
            for y in range(2,10):
                remainder = c%y
				if remainder != 0:
                    print(c)
 
print("end program")
#line 15
#if remainder != 0: #TabError: inconsistent use of tabs and spaces in indentation ^
Reply
#2
(Feb-03-2019, 12:46 PM)anfaenger Wrote: I simply cannot see how indentation is inconsistent.

We also cannot see as you didn't use Python tags and there is no intentation.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
you mix tabs and spaces for indentation and that is why you get the error. The recommendation is to use spaces (4 spaces).
Most IDE would have option to convert tabs to spaces automatically.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thank you Buran, you identified the problem. I didn't use tags because I've no idea what they are and how to use them. And yes, I've read the explanation.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Re Try loop for "net use..." failures tester_V 10 447 Mar-02-2024, 08:15 AM
Last Post: tester_V
  File loop curiously skipping files - FIXED mbk34 10 685 Feb-10-2024, 07:08 AM
Last Post: buran
  Optimise multiply for loop in Python KenBCN 4 428 Feb-06-2024, 06:48 PM
Last Post: Gribouillis
  Basic binary search algorithm - using a while loop Drone4four 1 309 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  loop through csv format from weburl in python maddyad82 3 358 Jan-17-2024, 10:08 PM
Last Post: deanhystad
  Variable definitions inside loop / could be better? gugarciap 2 375 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  UART & I2C slow down a loop trix 4 545 Dec-28-2023, 05:14 PM
Last Post: trix
  Need an alternative to brute force optimization loop jmbonni 5 1,107 Dec-07-2023, 12:28 PM
Last Post: RockBlok
  Which GUI can have indefinite loop ? jst 20 1,579 Nov-16-2023, 10:23 PM
Last Post: jst
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,526 Nov-07-2023, 09:49 AM
Last Post: buran

Forum Jump:

User Panel Messages

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