2013-11-27 47 views
0

我被我的程序卡住了。基本上我必須調用一個模塊,並讓該模塊創建一個文件,其中包含稍後在程序中提到的值。但是,該模塊無法正常工作,我不確定哪裏出錯。提前致謝。這是我目前的計劃。Python:模塊將「無」值返回到創建的文件中

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) 

回答

1

powerval函數沒有return語句。

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 # <---- 
+0

謝謝!這清除了它。 – KwakKwak