这是我第一次向stackoverflow发帖
创建和使用这些变量的有效方法是什么
lowerCharsEnabled = True
upperCharsEnabled = True
digitCharsEnabled = True
specialCharsEnabled = True
这个功能可以完成这项工作,但据我所知,这并不是最有效的方式
def usedChars():
global finalChars
if lowerCharsEnabled == True:
finalChars = lowerChars
if upperCharsEnabled == True:
finalChars = finalChars + upperChars
if digitCharsEnabled == True:
finalChars = finalChars + digitChars
if specialCharsEnabled == True:
finalChars = finalChars + specialChars
期待您的建议,如有任何帮助,将不胜感激
完整的程序代码供参考
import random
import string
lowerChars = string.ascii_lowercase
upperChars = string.ascii_uppercase
digitChars = string.digits
specialChars = string.punctuation
lowerCharsEnabled = True
upperCharsEnabled = True
digitCharsEnabled = True
specialCharsEnabled = True
finalChars = ""
passLen = 8
def usedChars():
global finalChars
if lowerCharsEnabled == True:
finalChars = lowerChars
if upperCharsEnabled == True:
finalChars = finalChars + upperChars
if digitCharsEnabled == True:
finalChars = finalChars + digitChars
if specialCharsEnabled == True:
finalChars = finalChars + specialChars
def generatePass():
try:
password = "".join(random.choice(finalChars) for x in range(passLen))
print(password)
except:
print("Cant Generate Pass")
usedChars()
generatePass()
input("Waiting...")
最后的答案谢谢大家
相关问题 更多 >
编程相关推荐