2016-04-18 7 views
1

からリストを渡して、私は問題を抱えているし、まだ解決策を見つけていない:(問題 - のelifがオプション・メニュー

、私はいくつかの評価を行うことができ、そこからメインのデータベースを持っていると思います

は、このコードを見てください:

def main(): 
    # Hauptmenue 
    screen() # Options-Screen 
    choice = ask_choice() # simple input routine 
    if choice == "l": # load database 
     mftemp = laden() # load database into mftemp 
     print("********MF-Gesamt im Main********") # just to check if 
     for i in range(len(mftemp)):    # datase is present 
      print(mftemp) 
     print("********Laden-Fertig***********") 
     mfgesamt = mftemp # see comment (1) 
    elif choice == "h": # I want to do some calculation here 
     print("MF-Gesamt-Hilfe") 
     mfgesamt2 = hilfe(mfgesamt) # Error, see comment (2) 
     for i in range(len(mfgesamt2)): 
      print(mfgesamt2) 
    elif choice == "q": 
     exit() 
    else: 
     print("Auswahl nicht vorhanden") 
    print("********Main*ein**********") # see comment (3) 
    for i in range(len(mftemp)): 
     print(mftemp) 
    print("********Main*aus**********") 
    mfgesamt = mftemp 
    main() 

私は何をしたい: タイプ「L」と負荷データベース タイプ「時間」とロードしたデータベース上のいくつかの計算を行う

コメント(1):データベースが正常に読み込まれました。mfgesamtとmftempが必要なコンテンツを表示しています。エラー:ローカル変数 'mfgesamt'が代入の前に参照されました 変数を使って多くの反復を試み、ルーチンに入れてメインに配置しました。あなたはどこを見て、このエラーを取り除くために私にいくつかのヒントやアドバイスを与えることができますしてください場合はロードした後、データがうまく表示されている、などのコメントで(1)

:何も

コメント(3)を働きました。 メインルーチンを再び起動すると変数が消去されるようです。 しかし、私はそれをどのように修正するか考えていません。 (後藤は参考になります:)

私のプログラミングの経験は、C128とどんぐり-Basicからいくつかの基本的なビット「さび」です:)

はあなたの助けをありがとうございました。あなたが代わりに再帰のループを使用する必要があります AndreWas

答えて

0

は、その後、あなたの変数はそのまま残る

def main(): 
    while True: 
     # Hauptmenue 
     screen() # Options-Screen 
     choice = ask_choice() # simple input routine 
     if choice == "l": # load database 
      mftemp = laden() # load database into mftemp 
      print("********MF-Gesamt im Main********") # just to check if 
      for i in range(len(mftemp)):    # datase is present 
       print(mftemp) 
      print("********Laden-Fertig***********") 
      mfgesamt = mftemp # see comment (1) 
     elif choice == "h": # I want to do some calculation here 
      print("MF-Gesamt-Hilfe") 
      mfgesamt2 = hilfe(mfgesamt) # Error, see comment (2) 
      for i in range(len(mfgesamt2)): 
      print(mfgesamt2) 
     elif choice == "q": 
      exit() 
     else: 
      print("Auswahl nicht vorhanden") 
      print("********Main*ein**********") # see comment (3) 
      for i in range(len(mftemp)): 
       print(mftemp) 
      print("********Main*aus**********") 
      mfgesamt = mftemp 
+0

は、あなたの速い返事ありがとうございます!あなたの提案をして、メインルーチンにローディングルーチンを入れました。うまくいきます。 –

+0

次に、[回答を受け入れる](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Thomas