我需要一个存储来自我的addmassage()函数的返回数据的地方,以便稍后引用。我想在没有全局变量的情况下这样做,但这可能吗?这是我的一些代码。
def mainFunction():
massageList = [0, 0, 0]
"""This function hosts the menu and """
print "Make a selection:"
print "1. Add a massage to my schedule"
print "2. View my current schedule"
print "3. Cancel a massage from my schedule"
print "4. Calculate fundraising total"
print "5. Quit"
selection = raw_input("Your selection:")
if selection == "1":
addMassage1 = addMassage()
massageList[0] = massageList[0] + addMassage1[0]
massageList[1] = massageList[1] + addMassage1[1]
massageList[2] = massageList[2] + addMassage1[2]
print massageList
mainFunction()
if selection == "2":
print massageList
mainFunction()
def addMassage():
massageList = [0, 0, 0]
massageType = raw_input("Add a (1) 15 minute, (2) 30 minute, or (3) 60 minute massage")
if massageType == "1":
massageList[0] = massageList[0] + 1
if massageType == "2":
massageList[1] = massageList[1] + 1
if massageType == "3":
massageList[2] = massageList[2] + 1
return massageList
enter code here
答案 0 :(得分:0)
你可以将它输出到一个单独的文件,然后让程序稍后读取它,但如果你不小心对文件做了什么,这可能会搞砸......