我被我的程序困住了。基本上我必须调用一个模块并让该模块创建一个文件,其中包含我稍后在程序中引用的值。但是,该模块无法正常工作,我不知道我哪里出错了。提前致谢。这是我目前的计划。
import math
import mymath
def main():
getData()
summer()
def getData():
powerfile = open("myfile.dat","w")
fin = open("sample.dat","r")
done = False
while not done:
x = int(fin.readline())
if x < 0:
done = True
else:
y = int(fin.readline())
answer = mymath.powerval(x,y)
answer = str(answer)+'\n'
powerfile.write(answer)
powerfile.close()
def summer():
file_in = open("myfile.dat","r")
total = 0
count = 0
for a in file_in:
number = int(a)
count += 1
total += number
file_in.close()
print("The final sum was", total)
close = input('')
main()
我的mymath模块:
import math
def powerval(x,y):
if x > y:
big = x
else:
small = x
if x > y:
small = y
else:
big = y
answer = pow(big, small)
答案 0 :(得分:1)
powerval
函数没有返回语句。
def powerval(x,y):
if x > y:
big = x
else:
small = x
if x > y:
small = y
else:
big = y
answer = pow(big, small)
return answer # <----