【问题标题】:How to fix "Unindent does not match any outer indentation"如何修复“Unndent 不匹配任何外部缩进”
【发布时间】:2019-12-07 13:05:33
【问题描述】:

我正在制作一个简单的问卷,当我运行它时,它会说:

  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】:

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

缩进块中的所有代码行(例如if 语句)都需要具有完全相同的缩进。该错误很可能是由于第 55 行的制表符和空格混合造成的。

您可以尝试删除该行并再次输入configuring sublime text to display the whitespace

【讨论】:

  • 第 54 行和第 69 行有标签。不要删除该行,而是确认编辑器配置为使用空格而不是制表符,然后简单地取消缩进该行然后重新缩进它。或者告诉 Sublime 一次性用空格替换制表符,它会立即修复所有行。
猜你喜欢
  • 2012-07-04
  • 1970-01-01
  • 2019-06-28
  • 1970-01-01
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 2020-08-14
  • 1970-01-01
相关资源
最近更新 更多