Python Forum
Why interpreter accepts indentation made with spaces and not those by tabs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why interpreter accepts indentation made with spaces and not those by tabs
#3
For the whole file I used tabs. I used vim. It did not run well.
sylvain@sylvain-HP-Laptop-15-bw0xx:~$ cat new2.py
#!/usr/bin/python3
#!/usr/bin/env python3
#new2.py

def silly(n, x):
    m=n
    stack = [iter(range(m))]
    total=0
    while stack:
        try:
            i = stack[-1].__next__()
        except StopIteration:
            stack.pop()
            continue
        total += i   
        if total >= x:
            break
        if i ==  5:
            m -= 1
            stack.append(iter(range(m)))
    return total


print(silly(1,2))


print(silly(0,1))
print(silly(2,3))
print(silly(3,4))
										
sylvain@sylvain-HP-Laptop-15-bw0xx:~$ 
The first is for try: Instead of tabs I use spaces. Error repaired. Next error is for the next line.nd
It is really amazing ! How interpreter finds you used tabs and not spaces ???
Reply


Messages In This Thread
RE: Why interpreter accepts indentation made with spaces and not those by tabs - by sylas - Oct-17-2018, 05:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cmath.rect accepts a negative modulus JMB 2 410 Jan-17-2024, 08:00 PM
Last Post: JMB
  function accepts infinite parameters and returns a graph with those values edencthompson 0 920 Jun-10-2022, 03:42 PM
Last Post: edencthompson
  Buttons not working in tabs kenwatts275 2 1,461 May-02-2022, 04:45 PM
Last Post: kenwatts275
  PYQT charts in tabs frohr 10 4,626 Feb-13-2022, 04:31 PM
Last Post: Axel_Erfurt
  create new tabs and populate using python reggie4 2 2,323 Jan-23-2021, 11:25 PM
Last Post: Larz60+
  HELP TabError: inconsistent use of tabs and spaces in indentation blackjesus24 2 3,631 Jan-30-2020, 10:25 AM
Last Post: blackjesus24
  Setting Tabs in a listbox scratchmyhead 2 2,897 Nov-12-2019, 11:18 PM
Last Post: scratchmyhead
  removing spaces/tabs after used .strip() zarize 0 1,638 Sep-11-2019, 12:46 PM
Last Post: zarize
  removing tabs from input text jenya56 3 3,352 Mar-28-2019, 03:10 PM
Last Post: DeaD_EyE
  Writing a function that accepts a path to an input file says 3 3,400 Aug-29-2018, 05:20 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