python - 缩进错误: expected an indented block in python (using hard tabs)

标签 python tabs atom-editor

我已经检查并仔细检查了我的代码是否正确使用制表符进行缩进,而不是看起来像制表符的空格。我在 Max OS X 上使用 Atom 代码编辑器。我关于选项卡的设置如下:

  • 未选中软选项卡
  • 制表符大小设置为 4
  • 选项卡类型设置为硬

这是我的代码:

#Password Cracker test program
#Program written by Zach Hofmeister, ported to Python
#READ THE README BEFORE USING ANY OF MY CODE!!!

#Below variable saves the password entered by the user. Only compared to a complete password to simulate brute-force cracking.
userPassword = raw_input("Enter a 4 digit password for the computer to guess. Only Upper/Lower case letters and numbers.") + ""

#The following variable contains an array of all the possible characters that can be present.
possibleCharacters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0']

#The default computer guess.
computerGuess = 'AAAA'

#Establishes that the computer has not correctly guessed the password, will be changed when password is discovered.
correctGuess = False

#The following variable keeps track of how many guesses it takes for the computer to crack the password.
totalGuesses = 0

#The following variable keeps track of what character is currently being tested.
i = [0,0,0,0,0,0,0,0,0,0]

#Function that compares the current guess to the user input. Notice that the password isn't guessed letter by letter, the whole 4 character guess is generated.
def checkPassword(passwordGuess):
    if (passwordGuess == userPassword):
        print "Your password is " + computerGuess + "."
        print "Took " + totalGuesses + " tries to guess your password."
    else:
        #print "Guessing again."

#Function that creates the current guess and compares it to the actual password.
def charGuess(charNumberDigit):
    computerGuess = computerGuess[0:charNumberDigit - 1] + possibleCharacters[i[charNumberDigit - 1]] + computerGuess[charNumberDigit:end]
    checkPassword(computerGuess)
    if (charNumberDigit != 4):
        i[charNumberDigit] = 0
    i[charNumberDigit - 1] += 1
    totalGuesses += 1

#The loop that tells the computer to try a guess
while (computerGuess != userPassword):
    while (i[3] <= 61 && computerGuess != userPassword):
        charGuess(4)
        while (i[2] <= 61 && i[3] == 61 && computerGuess != userPassword):
            charGuess(3)
            while (i[1] <= 61 && i[2] == 61 && computerGuess != userPassword):
                charGuess(2)
                while (i[0] <= 61 && i[1] === 61 && computerGuess != userPassword):
                    charGuess(1)

顺便说一句,我已经阅读了有关此问题的其他帖子,但它们没有解决我的问题,因为(据我所知)我正确使用了制表符,而不是制表符和空格的混合。

最佳答案

在Python中,代码块中总是必须有一些东西。您已注释掉 checkPassword 函数中的 else block 。

def checkPassword(passwordGuess):
    if (passwordGuess == userPassword):
        print "Your password is " + computerGuess + "."
        print "Took " + totalGuesses + " tries to guess your password."
    else:
        #print "Guessing again."

您可以使用pass如果您不想做任何事情,请声明:

else:
    pass

关于python - 缩进错误: expected an indented block in python (using hard tabs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36289649/

相关文章:

javascript - 如何使用 Jasmine 1.3.1 和 Atom 进行异步测试

python - 从 flask 中的 matplotlib 绘制 png 图显示原始数据

java - android 标签布局错误

python - 如何分析 Python 脚本?

C# 如何在多个窗口中从 chrome 获取标签?

android - 如何使用每个选项卡的图像和 ActionBarSherlock 设置选项卡宽度

css - 我在 Atom 中写了我的 style.css 然后它崩溃了所以它现在是空白的,但我已经在浏览器中打开了网页

python - 如何设置 Atom 的脚本来运行 Python 3.x 脚本?与 Windows 7 Pro x64 的组合可能是问题所在吗?

python - 实际上,在 OSX Mountain Lion 上安装了太多的 Python

python - 将 SQL Server 的 Linux ODBC 驱动程序添加到 Kaggle/Python docker 镜像