我创建了一个input.txt文件。 input.txt中有几组测试输入日期。然后我在终端python Filename.py <input.txt >output.txt
中运行。运行后我只得到第一组输入日期的输出。如何在output.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 )
答案 0 :(得分:0)
我觉得你没有添加任何循环来遍历txt文件中的所有输入。这可能会有所帮助:
从fp = open('input.txt')
开始。添加for
循环,例如for i, line in enumerate(fp.readlines()):
,然后输入您为获取值并打印邮件而添加的代码。