缩进错误:在python中应为缩进块(使用硬制表符)
我已经检查并再次检查了我的代码是否正确地使用了缩进标签,而不是看起来像标签的空格。我正在Max OS X上使用atom代码编辑器。我对选项卡的设置如下:缩进错误:在python中应为缩进块(使用硬制表符),python,tabs,atom-editor,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!!!
- 未选中软选项卡
- 选项卡大小设置为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)
密码破解测试程序
#Zach Hofmeister编写的程序,移植到Python
#在使用我的任何代码之前,请阅读自述文件!!!
#下面的变量保存用户输入的密码。只有比较完整的密码才能模拟暴力破解。
userPassword=raw_input(“输入一个4位数的密码供计算机猜测。只有大写/小写字母和数字。”)+“”
#以下变量包含可能存在的所有可能字符的数组。
此外,亦有“G”、“H”、“I”、“I”、“J”、“K”、“L”、“L”、“L”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“我”、“R”、“我”、“我”、“他们”、“他们”、“T”、“单位”、“单位”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、“他们”、““,”U“,”V“,”W“,”X“,”Y“,”Z“,”1“,”2“,”3“,”4“,”5“,”6“,”7“,”8“,”9“,”0“]
#默认的计算机猜测。
computerGuess='AAAA'
#确定计算机未正确猜出密码,将在发现密码时更改。
猜错
#以下变量跟踪计算机破解密码所需的猜测次数。
总猜测数=0
#以下变量跟踪当前正在测试的角色。
i=[0,0,0,0,0,0,0,0,0,0]
#将当前猜测与用户输入进行比较的函数。请注意,密码不是一个字母一个字母猜出来的,而是生成整个4个字符的猜测。
def checkPassword(密码猜测):
如果(passwordGuess==userPassword):
打印“您的密码为”+computerGuess+”
打印“take”+totalguesss+“尝试猜测您的密码。”
其他:
#打印“再次猜测”
#创建当前猜测并将其与实际密码进行比较的函数。
def charGuess(charNumberDigit):
computerGuess=computerGuess[0:charNumberDigit-1]+可能字符[i[charNumberDigit-1]]+computerGuess[charNumberDigit:end]
检查密码(计算机猜测)
如果(charNumberDigit!=4):
i[charNumberDigit]=0
i[charNumberDigit-1]+=1
总猜测数+=1
#告诉计算机尝试猜测的循环
while(computerGuess!=用户密码):
在Python中,(i[3]代码块中必须有某些内容。您已经在checkPassword函数中注释掉了else块
def checkPassword(passwordGuess):
if (passwordGuess == userPassword):
print "Your password is " + computerGuess + "."
print "Took " + totalGuesses + " tries to guess your password."
else:
#print "Guessing again."
如果您不想做任何事情,可以使用该语句:
else:
pass
问题出在else块中。您注释掉了下一行,因此它认为
charGuess
下面的函数是else块的一部分。如果不想发生任何事情,您可以在else块下编写pass
。