[问题] print画面资料 写出一个档

楼主: newdas (.)   2018-12-08 23:01:37
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()
===========================================================
作者: swampni   2018-12-09 10:34:00
试试看file.write()

Links booklink

Contact Us: admin [ a t ] ucptt.com