Python导入二维表数据
根据提示,在右侧编辑器补充代码,将二维表中的数据按格式写入到文件中。其中二维表的数据为:
data = [[ 0.75, 0.29619813, -0.29619813, -0.75 ],
[ 0.29613, 0.116978, -0.117778, -0.29613],
[-0.29, -0.11698, 0.11697778, 0.29619813],
[-0.75, -0.29619813, 0.29619813, 0.75 ]]``
文件保存的位置为: src/step3/output/data.txt 。
#coding=utf-8
def write_file():
# 请在此处填写代码
#********** Begin **********#
data = [[ 0.75, 0.29619813, -0.29619813, -0.75 ],
[ 0.29613, 0.116978, -0.117778, -0.29613],
[-0.29, -0.11698, 0.11697778, 0.29619813],
[-0.75, -0.29619813, 0.29619813, 0.75 ]]
outfile=open("src/step3/output/data.txt",'w')
for row in data:#遍历行
for column in row:#遍历每一个元素
outfile.write('%14.8f' % column)
outfile.write("\n")
outfile.close