2017-11-12 10 views
-2

パスワードチェッカーとメニュー付きの発電機を作っていますが、パスワードチェッカーはそれ自体でうまく動作しますが、メニューはコードと一緒には機能しません。それは自分自身でメニューを試してみるとどちらもうまくいかない。これらは私が受け取っているエラーです:def issue - NameError:name 'passwordchecker'が定義されていません

私は間違って何をしたのか分かりませんので、できるなら助けてください。

私はあなたがpasswordchecker()passwordgenerator()の定義以下にmainmenu()にごコールを移動する必要が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") 
+1

'mainmenu()'では、以下に定義されている 'passwordchecker()'を呼び出しています。 'mainmenu()'の上に 'passwordchecker()'関数を追加してください。 –

+1

@JasiuCzajka彼は実際に定義する前に関数を呼び出すと言っています。 –

答えて

0
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") 
0

を使用しています。それ以外の場合は、mainmenu()が呼び出すときには定義されません。

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() 
0

定義される前にいくつかの関数が呼び出されたようです。 mainmenu()の前にpasswordgenerator()とpasswordchecker()を置き、あなたが好きなように呼び出す。

また、このプログラムをループに入れて、 というループを変数に依存させることをお勧めします。そんなにエレガントになるでしょう。次に、あなたの関数の名前を次のように変更します。

mainMenu() 
passwordGenerator() 
passwordChecker() 

もっとプロフェッショナルに見えます。がんばろう!

+0

これは何も修正しません。問題は 'passwordchecker()'と 'passwordgenerator()'が定義される前に 'mainmenu()'が呼び出されていることです。これはあなたのコードでも起こります。 –

+0

ああ。私はその2つのメインメニュー()を認識しませんでした。ありがとうございました!今編集中。 – AllAmericanProgrammer

関連する問題