Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的加密程序需要帮助吗_Python_Python 2.7 - Fatal编程技术网

Python 我的加密程序需要帮助吗

Python 我的加密程序需要帮助吗,python,python-2.7,Python,Python 2.7,说明: 编辑:我只需要方法菜单返回“即将到来”,因为-就目前而言,如果用户输入c、p或s,它将不返回任何内容。我不明白为什么 def PrintDescription(): print 'This program encrypts and descrypts messages using multiple \ encryption methods.\nInput files must be in the same directory as this program.\ \nOutput

说明:

编辑:我只需要方法菜单返回“即将到来”,因为-就目前而言,如果用户输入c、p或s,它将不返回任何内容。我不明白为什么

def PrintDescription():
    print 'This program encrypts and descrypts messages using multiple \
encryption methods.\nInput files must be in the same directory as this program.\
\nOutput files will be created in this same directory.'

def StartMenu():
    print 'Do you wish to encrypt or decrypt?'
    print '<e>ncrypt'
    print '<d>ecrypt'
    print '<q>uit'

def MethodMenu():
  print 'Which method would you like to use?'
  print '<c>aesarian fixed offset'
  print '<p>seudo-random offset'
  print '<s>ubstitution cipher'
  a = raw_input("")
  while a not in ('c', 'p', 's'):
    if a:
      print "Error: You must type c, p, or s"
      a = raw_input("")
    if a == 'c' or a=='p' or a=='s':
      print 'Coming Soon'         

def main():
    alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.?! \t\n\r"
    PrintDescription()
    a = None
    while a not in ('e', 'd', 'q'):
        if a:
            print "Error: You must type e, d, or q"
        else:
            StartMenu()
        a = raw_input("")
        if a == 'e' or a=='d':
          MethodMenu()
        if a == 'q':
          break  

main()
def PrintDescription():
“打印”此程序使用多个\
加密方法。\n输入文件必须与此程序位于同一目录中\
\nOutput文件将在此同一目录中创建。'
def STARTMANU():
打印“您希望加密还是解密?”
打印“ncrypt”
打印“ecrypt”
打印“uit”
def MethodMenu():
打印“您希望使用哪种方法?”
打印“aesarian固定偏移”
打印“seudo随机偏移”
打印“替换密码”
a=原始输入(“”)
当a不在('c','p','s')中时:
如果是:
打印“错误:必须键入c、p或s”
a=原始输入(“”)
如果a=='c'或a=='p'或a=='s':
打印“即将到来”
def main():
alphabet=“abcdefghijklmnopqrstuvxyzabefghijklmnopqrstuvxyzo123456789,.?!\t\n\r”
PrintDescription()
a=无
而a不在('e','d','q'):
如果是:
打印“错误:必须键入e、d或q”
其他:
开始菜单()
a=原始输入(“”)
如果a=='e'或a=='d':
方法菜单()
如果a=='q':
打破
main()

在我介绍解决方案之前,这里有一些评论

  • MethodMenu()函数当前不返回任何内容。我想你是想返回用户的选择
  • 我看到StartMenu()和MethodMenu()之间有一种模式:每个模式都显示一个选项列表,并重复获取用户的输入,直到用户输入正确的输入。但是,StartMenu()函数不管理用户的输入,而MethodMenu()管理==>设计中的不一致性
  • 由于获取用户输入并验证它的行为会发生两次,因此最好将该代码块移动到一个单独的函数中,您可以调用该函数,而不是多次编写同一代码块
  • 我注意到单字母变量a的用户。一般来说,我建议使用更具描述性的名称,如用户选择、用户回答或用户输入
  • 我的解决方案是:

    def PrintDescription():
        print 'This program encrypts and descrypts messages using multiple \
    encryption methods.\nInput files must be in the same directory as this program.\
    \nOutput files will be created in this same directory.'
    
    def GetChoice(acceptable_answers):
        while True:
            user_choice = raw_input('')
            if user_choice in acceptable_answers:
                return user_choice
            else:
                print 'Please try:', ', '.join(acceptable_answers)
    
    def StartMenu():
        print 'Do you wish to encrypt or decrypt?'
        print '<e>ncrypt'
        print '<d>ecrypt'
        print '<q>uit'
        user_choice = GetChoice('edq')
        return user_choice
    
    def MethodMenu():
        print 'Which method would you like to use?'
        print '<c>aesarian fixed offset'
        print '<p>seudo-random offset'
        print '<s>ubstitution cipher'
        user_choice = GetChoice('cps')
        return user_choice
    
    def main():
        alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.?! \t\n\r"
        PrintDescription()
    
        while True:
            user_choice = StartMenu()
            if user_choice in ('e', 'd'):
                user_choice = MethodMenu()
                # Do something based on the user_choice
            if user_choice == 'q':
                break
    
    main()
    
    def PrintDescription():
    “打印”此程序使用多个\
    加密方法。\n输入文件必须与此程序位于同一目录中\
    \nOutput文件将在此同一目录中创建。'
    def GetChoice(可接受的回答):
    尽管如此:
    用户选择=原始输入(“”)
    如果用户在可接受答案中选择:
    返回用户选择
    其他:
    打印“请尝试:”、“、”。加入(可接受的答案)
    def STARTMANU():
    打印“您希望加密还是解密?”
    打印“ncrypt”
    打印“ecrypt”
    打印“uit”
    用户_choice=GetChoice('edq')
    返回用户选择
    def MethodMenu():
    打印“您希望使用哪种方法?”
    打印“aesarian固定偏移”
    打印“seudo随机偏移”
    打印“替换密码”
    用户_choice=GetChoice('cps')
    返回用户选择
    def main():
    alphabet=“abcdefghijklmnopqrstuvxyzabefghijklmnopqrstuvxyzo123456789,.?!\t\n\r”
    PrintDescription()
    尽管如此:
    用户选择=开始菜单()
    如果用户在('e','d')中选择:
    用户选择=方法菜单()
    #根据用户的选择做一些事情
    如果用户_选择=='q':
    打破
    main()
    
    更新
    如果您必须知道
    MethodMenu()
    有什么问题,这里有一个解释:用户第一次键入正确的选项(c、p或s):跳过整个while循环,这意味着不会打印“即将到来”。您可以修改您的解决方案,也可以使用hek2mgl。在我介绍解决方案之前,这里有几点意见

  • MethodMenu()函数当前不返回任何内容。我想你是想返回用户的选择
  • 我看到StartMenu()和MethodMenu()之间有一种模式:每个模式都显示一个选项列表,并重复获取用户的输入,直到用户输入正确的输入。但是,StartMenu()函数不管理用户的输入,而MethodMenu()管理==>设计中的不一致性
  • 由于获取用户输入并验证它的行为会发生两次,因此最好将该代码块移动到一个单独的函数中,您可以调用该函数,而不是多次编写同一代码块
  • 我注意到单字母变量a的用户。一般来说,我建议使用更具描述性的名称,如用户选择、用户回答或用户输入
  • 我的解决方案是:

    def PrintDescription():
        print 'This program encrypts and descrypts messages using multiple \
    encryption methods.\nInput files must be in the same directory as this program.\
    \nOutput files will be created in this same directory.'
    
    def GetChoice(acceptable_answers):
        while True:
            user_choice = raw_input('')
            if user_choice in acceptable_answers:
                return user_choice
            else:
                print 'Please try:', ', '.join(acceptable_answers)
    
    def StartMenu():
        print 'Do you wish to encrypt or decrypt?'
        print '<e>ncrypt'
        print '<d>ecrypt'
        print '<q>uit'
        user_choice = GetChoice('edq')
        return user_choice
    
    def MethodMenu():
        print 'Which method would you like to use?'
        print '<c>aesarian fixed offset'
        print '<p>seudo-random offset'
        print '<s>ubstitution cipher'
        user_choice = GetChoice('cps')
        return user_choice
    
    def main():
        alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.?! \t\n\r"
        PrintDescription()
    
        while True:
            user_choice = StartMenu()
            if user_choice in ('e', 'd'):
                user_choice = MethodMenu()
                # Do something based on the user_choice
            if user_choice == 'q':
                break
    
    main()
    
    def PrintDescription():
    “打印”此程序使用多个\
    加密方法。\n输入文件必须与此程序位于同一目录中\
    \nOutput文件将在此同一目录中创建。'
    def GetChoice(可接受的回答):
    尽管如此:
    用户选择=原始输入(“”)
    如果用户在可接受答案中选择:
    返回用户选择
    其他:
    打印“请尝试:”、“、”。加入(可接受的答案)
    def STARTMANU():
    打印“您希望加密还是解密?”
    打印“ncrypt”
    打印“ecrypt”
    打印“uit”
    用户_choice=GetChoice('edq')
    返回用户选择
    def MethodMenu():
    打印“您希望使用哪种方法?”
    打印“aesarian固定偏移”
    打印“seudo随机偏移”
    打印“替换密码”
    用户_choice=GetChoice('cps')
    返回用户选择
    def main():
    alphabet=“abcdefghijklmnopqrstuvxyzabefghijklmnopqrstuvxyzo123456789,.?!\t\n\r”
    PrintDescription()
    尽管如此:
    用户选择=开始菜单()
    如果用户在('e','d')中选择:
    用户选择=方法菜单()
    #根据用户的选择做一些事情
    如果用户_选择=='q':
    打破
    main()