0

I want to build a table like the following with Python.

0 1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
6 7 8 9 10 11 12

The code is like this

i = 0
j = 0
total = 6

while j <= total:
    while i <= total:
        print(i, "\t", end="")
        i += 1
        print("")
    j += 1

I got an error "unindent does not match any outer indentation level", which says "j += 1" was wrong. I use Sublime Text 3 as my IDE. Please tell me what went wrong and how to fix it?

3
  • 1
    The indentation might be an issue related to your text editor. ITworked with my PC. However, your loop is wrong, you won't get the exepected result. In addition, your code is not pythonic at all. You should consider using a single loop for... in range(x, y) instead. Commented Oct 28, 2015 at 16:03
  • when you figure out your indentation you might try printing i and j in the second print, you might see something interesting Commented Oct 28, 2015 at 16:07
  • Could you correct my loop with "while way"? Thank you. Commented Oct 28, 2015 at 16:25

1 Answer 1

1

Which IDE are you using? Recall that Python is sensitive to spacing and recall that the "indents" are not actually Tabs, they are EXACTLY four spaces (no more no less). So I would confirm that your IDE is set accordingly and maybe try manually spacing your items out.

Sign up to request clarification or add additional context in comments.

3 Comments

I use Sublime Text 3 on windows. Thanks for your help.
@torinchien I don't know much about that editor but I would check to make sure that the Tab settings are set to 4 spaces. I think the default on most text programs is 5? A setting like that would definitely cause the error you describe
@JimBeam Look at the lower right hand corner of your editor. You should see something like Tab and Python. Click Tab and change it to 4 spaces. There is probably a setting somewhere to change this for all Python files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.