我的代码中有一个函数需要两个参数
def cost_per_student(nparrloans,nparrrecipients):
nparrloanperstudent = (nparrloans)*1000000000/(nparrrecipients)*1000000
return nparrloanperstudent
每当我运行我的代码时,它都会转到此函数,说我的nonetype和int有不受支持的操作数。有没有办法使之成为可能,我尝试将nonetypes转换为int但无济于事
这是我其余的代码
from csv import *
import numpy as np
import matplotlib.pyplot as plt
#Step 5
def read_data(filename):
try:
array = np.genfromtxt("filename", delimiter=',', usecols=(1,2,3,4,5,6))
except IOError:
print("File not found")
#Step 6
def cost_per_student(nparrloans,nparrrecipients):
nparrloanperstudent = (nparrloans) *1000000000/(nparrrecipients)*1000000
return nparrloanperstudent
#Step 7
def read_labels(filename):
labels= []
try:
labelFile = open(filename, "r")
for line in labelFile:
line.strip()
line.title()
lables.append(line)
labelFile.close()
except IOError:
print("Label file not found")
return labels
#Step 8
def display_amounts_whole(npdata, labels, title):
labels = labels
sizes = npdata
plt.title(title)
plt.show()
#Step 9
def write_averages_to_file(filename,labels,averages):
if len(labels) == len(averages):
try:
file = open(filename, ' w' , newline='')
csvfile = csv.writer(file, delimiter = ',')
for i in range(len(labels)):
csvfile.writerow(labels, averages)
csvfile.close()
except IOError:
print("Output file not valid")
else:
print("Labels do not match average")
#Step 10
def main():
loanamts = read_data("Loan_amounts_by_type_data.csv")
population = read_data("Loan_amounts_by_type_number.csv")
dataLabels = read_labels("loan_types.txt")
calculation = cost_per_student(loanamts, population)
display_amounts_whole(population, dataLabels, "Loan Amounts by Type\n4th
Quarter 2017")
#Step 11
if __name__ == "__main__":
main()
答案 0 :(得分:0)
调用函数时,其中一个值(nparrloans,nparrrecipients)为none。
如果您确定自己的代码正确,那么我认为它需要一些组织,因此,当您调用
同时定义了两个参数(nparrloans,nparrrecipients)的函数。