擅长:python、mysql、java
<p>可以使用Python中的内置<a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow noreferrer">open</a>函数创建文件:</p>
<pre><code>with open('output.txt', 'w') as outfile:
outfile.write("pline\n")
l = int(input('l='))
r = int(input('r='))
for x in range(0, l + 1, 2):
y = round(((x ** 3) / (6 * l * r)), 4)
for x in range(0, l + 1, 2):
outfile.write("{},{}\n".format(x, round(((x ** 3) / (6 * l * r)), 4)))
</code></pre>
<p><strong>输出</strong></p>
^{pr2}$
<p>函数<code>outfile.write</code>将文本写入文件,在上面的示例<code>outfile</code>。要写一行,必须在所写的每个字符串的末尾附加换行符<code>\n</code>。在</p>