晚上好,我正在尝试为自己正在构建的用于练习数学数学的程序构建一个菜单系统。想法是,在下面的子菜单(sub1)中选择选项“ 1”会使函数two_by_three_mult(在选择“ 1”时调用)中生成的介绍性对话发生变化,以反映所做的选择。但是,如果选择选项“ 1”,则intro_dialogue变量不会更改为等于“ 2位数乘3位数乘法”,这意味着当two_by_three_mult函数运行时,不会显示正确的消息。
我认为出现此问题是因为我试图调用一个函数(two_by_three_mult)并更改该函数在同一IF子句中使用的变量(intro_dialogue),但是我无法弄清楚如何格式化我的代码来解决此问题。 / p>
def sub1():
sub1_1 = int((raw_input("""Welcome to the practice area. What would you like to practice?
1:2-digit by 3-digit multiplication
2:Anything else
""")))
if sub1_1 == 1:
def printHam():
intro_dialogue = "2-digit by 3-digit multiplication"
two_by_three_mult()
elif sub1_1 == 2:
sub12_1 =(raw_input("""under construction. press 'm' to return to the main menu. Press any other button to exit
"""))
if sub12_1 == "m":
main_menu()
def two_by_three_mult():
import random
questions = int((raw_input("Welcome to the %s multiplication programme.
How many questions do you wish to attempt? "%(str(intro_dialogue)))))