後で参照する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
あなたのコードのインデントは少しですこれはPythonコードでは混乱の原因となる可能性があります。あなたの質問に対処しようとすると、オブジェクトを使用したり、独自のクラスを作成してマッサージリストを管理することをお勧めします。 – Laurent