2016-10-07 4 views
0

input.txtファイルを作成しました。 input.txtにいくつかのテスト入力日付のセットがあります。それから私はターミナルpython Filename.py <input.txt >output.txtで走ります。実行した後、私は最初に設定された入力日付の出力を取得します。 output.txtにすべての出力日付を自動的に取得するにはどうすればよいですか?txtファイルでテストする

# GET amount of money in bank 
amount_in_bank = input("How much money is in the bank? $") 
# GET amount of income 
amount_of_income = input("How much income is expected? $") 
# GET amount of expenses 
amount_of_expenses = input("How much money is going to be spent on expenses? $") 
# CALCULATE money in bank + income - expenses 
# SET amount available to result of previous calculation 
amount_available = int(amount_in_bank) + int(amount_of_income) - int(amount_of_expenses) 
# DISPLAY amount available 
message = "Bobbie will have $" + str(amount_available) + " left at the end of the month." 
print (message) 
+11

Pythonコードを共有する –

+0

あなたのプログラムは(それだけであると仮定して)一度何かします。一度それをする部分はどこですか? –

+0

Pythonコードでループが必要なように見えるので、すべての入力を処理します。 – Barmar

答えて

0

txtファイルのすべての入力をトラバースするためにループを追加していないと感じます。これは役立つかもしれません:

から始まるfp = open('input.txt')for i, line in enumerate(fp.readlines()):のようなループをforに追加し、値を取得しメッセージを印刷するために追加したコードを入力します。