Python 我的加密程序需要帮助吗
说明: 编辑:我只需要方法菜单返回“即将到来”,因为-就目前而言,如果用户输入c、p或s,它将不返回任何内容。我不明白为什么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
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()
在我介绍解决方案之前,这里有一些评论
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。在我介绍解决方案之前,这里有几点意见
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()