-2
我试图在Python 2.7中创建一个功耗计算器程序。它工作,但我试图将值写入一个文件和/ n不起作用。这里是该程序:新行(/ n)在Python 2中不工作
import math
file = open("numbers.txt" , 'w')
c = 0
a = int(raw_input("A number: "))
b = int(raw_input("To the power "))
h = range(b)
h.append(b)
print 1
file.write('1')
for c in range(b):
print int((math.pow(a, h[c+1])))
k = (int((math.pow(a, h[c+1]))))
file.write((str(k)+"/n") `
这是'\ n'。不是'/ n' – NullDev
我已将此标记为脱离主题,理由是您的问题是由简单的印刷错误造成的。你想写'\ n'。 – ymbirtt
另请注意,*“不工作”*不是一个非常有用的问题描述;给[mcve]。 – jonrsharpe