Python def问题-名称错误:名称';密码检查器';没有定义
我正在制作一个密码检查器和一个带有菜单的生成器,密码检查器本身可以正常工作,但菜单不能与代码一起工作,我自己尝试过菜单,但也不能工作。以下是我收到的错误:Python def问题-名称错误:名称';密码检查器';没有定义,python,Python,我正在制作一个密码检查器和一个带有菜单的生成器,密码检查器本身可以正常工作,但菜单不能与代码一起工作,我自己尝试过菜单,但也不能工作。以下是我收到的错误: Traceback (most recent call last): File "C:/Users/Jasiu Czajka/PycharmProjects/untitled/First Code.py", line 41, in <module> mainmenu() File "C:/Users/Jasiu
Traceback (most recent call last):
File "C:/Users/Jasiu Czajka/PycharmProjects/untitled/First Code.py", line 41, in <module>
mainmenu()
File "C:/Users/Jasiu Czajka/PycharmProjects/untitled/First Code.py", line 24, in mainmenu
passwordchecker()
NameError: name 'passwordchecker' is not defined
回溯(最近一次呼叫最后一次):
文件“C:/Users/Jasiu Czajka/PycharmProjects/untitled/First Code.py”,第41行,在
主菜单()
主菜单第24行的文件“C:/Users/Jasiu Czajka/PycharmProjects/untitled/First Code.py”
密码检查器()
NameError:未定义名称“passwordchecker”
我不确定我做错了什么,所以如果可以的话请帮忙
我使用pycharm和python 3.6.3
import re
def mainmenu():
print("*******************************************************************")
print(" Welcome to the Password Checker & Generator ")
print('*******************************************************************')
print("-------------------------------------------------------------------")
print("This program can be used to check a password to see if it is strong")
print("-------------------------------------------------------------------")
print("This Program can be used to generate strong passwords")
print("-------------------------------------------------------------------")
print("1. Password Checker")
print("-------------------------------------------------------------------")
print("2. Password Generator")
print("-------------------------------------------------------------------")
print("3. Exit")
print("-------------------------------------------------------------------")
print("*******************************************************************")
while True:
try:
selection = int(input("Enter choice: ")) # Making selection a variable
if selection == 1:
passwordchecker()
break
elif selection == 2:
passwordgenerator()
break
elif selection == 3:
exit()
break
else:
print("Invalid Choice. Enter 1-3")
mainmenu()
except ValueError:
print("Invalid Choice. Enter 1-3")
exit()
mainmenu()
def passwordchecker():
print("***************************************************************")
print(" PASSWORD CHECKER ")
print("***************************************************************")
print(" ")
print("---------------------------------------------------------------")
print("The password must be at least 8 characters, and a maximum of 24")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 uppercase letter")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 lowercase letter")
print("---------------------------------------------------------------")
print("The password must at least have 1 number in it")
print("---------------------------------------------------------------")
print('The password must have at least 1 symbol')
print("Allowed Symbols: !, $, %, ^, &, *, (, ), _, -, +, =, ")
print("---------------------------------------------------------------")
incorrectpassword = True
while incorrectpassword:
password = input("Type in your password: ")
if len(password) < 8:
print("Your password must be at least 8 characters long")
elif len(password) > 24:
print("Your password must be maximum 24 characters long")
elif not any(i.isdigit() for i in password):
print("You need a number in your password")
elif not any(i.isupper() for i in password):
print("You need a capital letter in your password")
elif not any(i.islower() for i in password):
print("You need a lowercase letter in your password")
elif re.search('[!, $, %, ^, &, *, (, ), _, -, +, =,]', password) is None:
print("You need a symbol in your password")
else:
print("Your password has all the characters needed")
incorrectpassword = False
passwordchecker()
mainmenu()
def passwordgenerator():
print("Work In Progress")
重新导入
def主菜单():
打印(“****************************************************************************************************************************”)
打印(“欢迎使用密码检查器和生成器”)
打印(“*******************************************************************************************************************************”)
打印(“----------------------------------------------------------------------------”)
打印(“此程序可用于检查密码是否强大”)
打印(“----------------------------------------------------------------------------”)
打印(“此程序可用于生成强密码”)
打印(“----------------------------------------------------------------------------”)
打印(“1.密码检查器”)
打印(“----------------------------------------------------------------------------”)
打印(“2.密码生成器”)
打印(“----------------------------------------------------------------------------”)
打印(“3.退出”)
打印(“----------------------------------------------------------------------------”)
打印(“****************************************************************************************************************************”)
尽管如此:
尝试:
selection=int(输入(“输入选项”)#将选择设置为变量
如果选择==1:
密码检查器()
打破
elif选择==2:
密码生成器()
打破
elif选择==3:
退出()
打破
其他:
打印(“无效选择。输入1-3”)
主菜单()
除值错误外:
打印(“无效选择。输入1-3”)
退出()
主菜单()
def passwordchecker():
打印(“*************************************************************************************************************”)
打印(“密码检查器”)
打印(“*************************************************************************************************************”)
打印(“”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少为8个字符,最多为24个”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少包含1个大写字母”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少包含1个小写字母”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码中必须至少包含1个数字”)
打印(“----------------------------------------------------------------------------------”)
打印('密码必须至少有1个符号')
打印(“允许的符号:!,$,%,^,&,*,(,),,-,+,=,”)
打印(“----------------------------------------------------------------------------------”)
密码不正确=真
密码不正确时:
密码=输入(“输入密码:”)
如果len(密码)<8:
打印(“您的密码长度必须至少为8个字符”)
elif len(密码)>24:
打印(“您的密码长度不得超过24个字符”)
如果没有(i.isdigit()表示密码中的i):
打印(“您的密码中需要一个数字”)
elif not any(i.isupper()表示密码中的i):
打印(“密码中需要大写字母”)
elif not any(i.islower()表示密码中的i):
打印(“密码中需要小写字母”)
elif搜索(“[!,$,%,^,&,*,(,),,-,+,=,]”,密码)为无:
打印(“密码中需要一个符号”)
其他:
打印(“您的密码包含所需的所有字符”)
密码不正确=错误
密码检查器()
主菜单()
def passwordgenerator():
打印(“正在进行的工作”)
重新导入
def passwordchecker():
打印(“*************************************************************************************************************”)
打印(“密码检查器”)
打印(“*************************************************************************************************************”)
打印(“”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少为8个字符,最多为24个”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少包含1个大写字母”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码必须至少包含1个小写字母”)
打印(“----------------------------------------------------------------------------------”)
打印(“密码中必须至少包含1个数字”)
打印(“----------------------------------------------------------------------------------”)
打印('密码必须至少有1个符号')
打印(“允许的符号:!,$,%,^,&,*,(,),,-,+,=,”)
打印(“----------------------------------------------------------------------------------”)
密码不正确=真
密码不正确时:
密码=输入(“输入密码:”)
如果len(密码)<8:
打印(“您的密码长度必须至少为8个字符”)
import re
def passwordchecker():
print("***************************************************************")
print(" PASSWORD CHECKER ")
print("***************************************************************")
print(" ")
print("---------------------------------------------------------------")
print("The password must be at least 8 characters, and a maximum of 24")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 uppercase letter")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 lowercase letter")
print("---------------------------------------------------------------")
print("The password must at least have 1 number in it")
print("---------------------------------------------------------------")
print('The password must have at least 1 symbol')
print("Allowed Symbols: !, $, %, ^, &, *, (, ), _, -, +, =, ")
print("---------------------------------------------------------------")
incorrectpassword = True
while incorrectpassword:
password = input("Type in your password: ")
if len(password) < 8:
print("Your password must be at least 8 characters long")
elif len(password) > 24:
print("Your password must be maximum 24 characters long")
elif not any(i.isdigit() for i in password):
print("You need a number in your password")
elif not any(i.isupper() for i in password):
print("You need a capital letter in your password")
elif not any(i.islower() for i in password):
print("You need a lowercase letter in your password")
elif re.search('[!, $, %, ^, &, *, (, ), _, -, +, =,]', password) is None:
print("You need a symbol in your password")
else:
print("Your password has all the characters needed")
incorrectpassword = False
def mainmenu():
print("*******************************************************************")
print(" Welcome to the Password Checker & Generator ")
print('*******************************************************************')
print("-------------------------------------------------------------------")
print("This program can be used to check a password to see if it is strong")
print("-------------------------------------------------------------------")
print("This Program can be used to generate strong passwords")
print("-------------------------------------------------------------------")
print("1. Password Checker")
print("-------------------------------------------------------------------")
print("2. Password Generator")
print("-------------------------------------------------------------------")
print("3. Exit")
print("-------------------------------------------------------------------")
print("*******************************************************************")
while True:
try:
selection = int(input("Enter choice: ")) # Making selection a variable
if selection == 1:
passwordchecker()
break
elif selection == 2:
passwordgenerator()
break
elif selection == 3:
exit()
break
else:
print("Invalid Choice. Enter 1-3")
mainmenu()
except ValueError:
print("Invalid Choice. Enter 1-3")
exit()
mainmenu()
passwordchecker()
mainmenu()
def passwordgenerator():
print("Work In Progress")
import re
def mainmenu():
print("*******************************************************************")
print(" Welcome to the Password Checker & Generator ")
print('*******************************************************************')
print("-------------------------------------------------------------------")
print("This program can be used to check a password to see if it is strong")
print("-------------------------------------------------------------------")
print("This Program can be used to generate strong passwords")
print("-------------------------------------------------------------------")
print("1. Password Checker")
print("-------------------------------------------------------------------")
print("2. Password Generator")
print("-------------------------------------------------------------------")
print("3. Exit")
print("-------------------------------------------------------------------")
print("*******************************************************************")
while True:
try:
selection = int(input("Enter choice: ")) # Making selection a variable
if selection == 1:
passwordchecker()
break
elif selection == 2:
passwordgenerator()
break
elif selection == 3:
exit()
break
else:
print("Invalid Choice. Enter 1-3")
mainmenu()
except ValueError:
print("Invalid Choice. Enter 1-3")
exit()
def passwordchecker():
print("***************************************************************")
print(" PASSWORD CHECKER ")
print("***************************************************************")
print(" ")
print("---------------------------------------------------------------")
print("The password must be at least 8 characters, and a maximum of 24")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 uppercase letter")
print("---------------------------------------------------------------")
print("The Password must contain at least 1 lowercase letter")
print("---------------------------------------------------------------")
print("The password must at least have 1 number in it")
print("---------------------------------------------------------------")
print('The password must have at least 1 symbol')
print("Allowed Symbols: !, $, %, ^, &, *, (, ), _, -, +, =, ")
print("---------------------------------------------------------------")
incorrectpassword = True
while incorrectpassword:
password = input("Type in your password: ")
if len(password) < 8:
print("Your password must be at least 8 characters long")
elif len(password) > 24:
print("Your password must be maximum 24 characters long")
elif not any(i.isdigit() for i in password):
print("You need a number in your password")
elif not any(i.isupper() for i in password):
print("You need a capital letter in your password")
elif not any(i.islower() for i in password):
print("You need a lowercase letter in your password")
elif re.search('[!, $, %, ^, &, *, (, ), _, -, +, =,]', password) is None:
print("You need a symbol in your password")
else:
print("Your password has all the characters needed")
incorrectpassword = False
passwordchecker()
def passwordgenerator():
print("Work In Progress")
mainmenu()
mainmenu()
mainMenu()
passwordGenerator()
passwordChecker()