Python “如何修复”;“未缩进与任何外部缩进不匹配”;
我正在做一份简单的调查问卷,当我运行它时,它说:Python “如何修复”;“未缩进与任何外部缩进不匹配”;,python,sublimetext3,indentation,Python,Sublimetext3,Indentation,我正在做一份简单的调查问卷,当我运行它时,它说: File "questionare.py", line 55 score -= 1 ^ IndentationError: unindent does not match any outer indentation level 然而,如果我试图修正它,它将忘记if语句,并扣除分数,即使该人得到了正确的答案。这是崇高文本的问题,还是我造成的问题?上面的代码没有这么说 代码如下: print() wemsg =
File "questionare.py", line 55
score -= 1
^
IndentationError: unindent does not match any outer indentation level
然而,如果我试图修正它,它将忘记if
语句,并扣除分数,即使该人得到了正确的答案。这是崇高文本的问题,还是我造成的问题?上面的代码没有这么说
代码如下:
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, "!")
您的代码为我运行,缩进看起来正确 缩进块中的所有代码行(如
if
语句)都需要完全相同的缩进。最有可能的错误是由于第55行的制表符和空格的混合
您可以尝试删除该行并再次键入。询问时,将代码减少到显示问题的最低限度。请参阅“”和“”及其所有链接页。代码有两行,54和69,具有单制表符缩进。第54和69行具有制表符。与其删除该行,不如确认编辑器已配置为使用空格而不是制表符,然后只需取消插入该行,然后重新插入它即可。或者告诉Sublime在一次传递中用空格替换制表符,它将立即修复所有行。