【发布时间】:2011-10-03 06:43:21
【问题描述】:
print "I can write my function to a txt file:"
my_function = raw_input("File name? ")
print_bills = input(bills(1010, 200, 100, 120))
open(my_function, 'w')
my_function.write('%r' % (print_bills))
my_function.close()
我正在使用 python 并试图将我的函数写入 txt 文件,函数是这样的
def bills(mortgage, elec, oil, ph_int_tv):
print "Our upcoming mortgage will be approximately %d /month)" % mortgage
print "Split between my brother and I, that will be %d /month" % (mortgage/2)
print "With a third roomate, it will be %d /month" % (mortgage/3)
print "My total bill, per month, with living costs included will be %d /month" % ((mortgage/2)+(elec/2)+(oil/2)+(ph_int_tv/2))
print "I better start saving money!!\n"
我很新,刚开始阅读 LPTHW 在线书籍...所以我的问题是,我可以在顶部代码中更改什么以使其正常工作...如果有的话?
【问题讨论】: