作者newdas (橘色天空)
看板Python
标题[问题] print画面资料 写出一个档
时间Sat Dec 8 23:01:37 2018
HI all
最近在修课时发现常常需要多次反覆执行计算
所以在思考 有没有办法让其 设定
1.设定重复执行几次
2.结果将每次结果写出 (已解决:)
还请大大可以指点 谢谢大家
=======================================================
def Queens():
status =
[0,1,2,3,4,5,6,7] #初始皇后都在对角线
#当存在冲突个数大於0时,循环球解最佳後继,直到找到最後一个皇后
while get_numof_conflict(status) > 0:
status = hill_climbing(status)
print status
print get_numof_conflict(status)
f = open("twice.txt", "a")
sys.stdout = f
print "the answer is"
print
print status
time.sleep(2)
tEnd = time.time()#计时结束
print "It cost %f sec" % (tEnd - tStart)#会自动做近位
#列印结果
file = open('data.txt','w+')
# print>>file
# file.close()
===========================================================
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.254.66.133
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1544281299.A.3F7.html
1F:推 swampni: 试试看file.write() 12/09 10:34
谢谢 s大 我换了一个作法 将print内容直接写在txt档
目前还剩 指定他 重复执行几次
※ 编辑: newdas (111.254.66.133), 12/09/2018 15:06:29
※ 编辑: newdas (111.254.66.133), 12/09/2018 15:46:32