2017-10-19 17 views
0

後で参照する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

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

答えて

0

あなたは可能性があり、別のファイルに出力するには、プログラムは後でそれを読んだことがあるが、その可能性が台無しに誤ってファイルに何かをしている場合...

+0

そのような例を提供してください。 – GiantsLoveDeathMetal

+0

#ストア出力、値などを変数に格納します。 –

+0

次に、f.write(variablename)、f.close()を実行すると、保存された値がnameoffile.txtという外部ファイルに出力されます。 –

関連する問題