【发布时间】:2015-03-23 14:13:49
【问题描述】:
我已经定义变量'method'的值并将其返回给一个名为method_menu的函数,然后尝试将它解析到main。我已经尝试了很多事情,但我无法弄清楚我哪里出错了。
这是我定义并返回“方法”的函数:
def method_menu():
#caeser or frequency
print()
print(".-METHOD MENU-----------------.")
print("| |")
print("| (C) Caesar Cipher |")
print("| (F) Frequency |")
print("| (Q) Quit |")
print("| |")
print("`-----------------------------'")
method = input("Press 'C' or 'F'").lower()
return method
这里是 main(尝试使用第 15 行和第 19 行的变量)我最初认为我必须使用 def main(method, text) 解析参数,但它无法识别:
def main():
# the main menu loop
while True:
# show the main menu and save their choice
main_choice = main_menu(main_menu)
# when they choose to quit break out of the infinite loop
if main_choice == 'q':
break
# user chooses to cipher
elif main_choice == 'c':
method_menu(method,text)
# user chooses to decipher
elif main_choice == 'd':
method_menu(method,text)
else:
print("Error - choice not recognised")
如果对任何人有用的话,这里是完整的程序:http://pastebin.com/e2M8K9Pa
有人能告诉我如何正确地将参数解析为 main 吗?
【问题讨论】:
标签: python parameters parameter-passing