如何修复“缩进不匹配任何外部缩进”

问题描述 投票:2回答:1

我正在制作一个简单的调查表,当我运行它时,它说:

  File "questionare.py", line 55
    score -= 1
             ^
IndentationError: unindent does not match any outer indentation level

但是,如果我尝试解决它,它将使if语句忘记并扣除分数,即使该人获得正确答案也是如此。 Sublime Text是否有问题,还是我引起的问题?它上面的代码没有这么说。

这里是代码:

print()
wemsg = print ("Welcome to the most holy questionnaire to exist!")
pointinst = print ("You will get 1 point for each correct question, you will get deducted 1 point with each wrong question!")

# used this video to configure python interpreter: https://www.youtube.com/watch?v=rIl0mmYSPIc

p1 = ("Question 1:")
p2 = ("Question 2:")
p3 = ("Question 3:")
p4 = ("Question 4:")
score = 0 # score worked: https://stackoverflow.com/questions/27337331/how-do-i-make-a-score-counter-in-python
print()

q1 = print(p1)
q1q = input("What is 1+1?: ")
print()

if q1q == ('2'):
    print ("Correct!")
    score += 1
    print ("Total score:", score)
if q1q != ('2'):
    print ("Incorrect!")
    score -= 1
    print ("Total score:", score)
    print ("The correct answer is", 1 + 1)
print()

q2 = print(p2)
q2q = input("What is 12 divided by 2 times 5?: ")
print()


if q2q == ('30'):
    print ("Correct!")
    score += 1
    print ("Total score:", score)
if q2q != ('30'):
    print ("Incorrect!")
    score -= 1
    print ("Total score:", score)
    print ("The correct answer is", int(12 / 2 * 5))
print()

q3 = print(p3)
q3q = input("What is 2 to the power of 3?: ")
print()

if q3q == ('8'):
    print ("Correct!")
score += 1
print ("Total score:", score)
if q3q != ('8'):
    print ("Incorrect!")
    score -= 1
    print ("Total score:", score)
    print ("The correct answer is", int(2 ** 3))
print()

q4 = print(p4)
q4q = input("What is (12 x 55) to the power of 6? (Calculator needed): ")
print()

if q4q == ('8.265395e+16'):
    print ("Correct, jesus that's a long number.")
score += 1
print ("Total score:", score)
if q4q != ('8.265395e+16'):
    print ("Bruh, you are using a Calculator how did you get this wrong.")
    score -= 1
    print ("Total score:", score)
    print ("The correct answer is", int(12 * 55 ** 6))
print()

finish = print ("You have finished the questionnaire with a total score of:", score, "!")
python sublimetext3 indentation
1个回答
3
投票

您的代码为我运行,并且缩进看起来正确。

[if语句之类的缩进块中的所有代码行都必须具有完全相同的缩进。该错误很可能是由于55行上的制表符和空格的混合。

您可以尝试删除该行,然后再次键入它,然后单击configuring sublime text to display the whitespace

© www.soinside.com 2019 - 2024. All rights reserved.