说明:
编辑:我只需要方法菜单返回“coming soon”,因为它是当前的状态,如果用户输入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()
按照您的逻辑,您应该将函数
MethodMenu()
更改为:但是为什么要用
a
而不是user_input
或其他什么东西?!你应该使用有表现力的变量名!;)在我提出我的解决方案之前,这里有一些意见。在
我的解决方案是:
更新
如果您必须知道
MethodMenu()
有什么问题,这里有一个解释:用户第一次键入正确的选择(c、p或s):整个while循环被跳过,这意味着不会打印“Coming Soon”。您可以修改您的解决方案,或者使用hek2mgl的。在相关问题 更多 >
编程相关推荐