python判断数值小于0时抛出异常处理的问题?
fromNumberErrorimport*defaverage(data):sum=0foriindata:ifi<0:raiseNumberError(str(i))...
from NumberError import *
def average(data):
sum=0
for i in data:
if i<0:
raise NumberError(str(i))
sum+=i
return sum/len(data)
if __name__=='__main__':
data1=(44,78,80,55)
print('平均值=',average(data1))
data2=(44,78,90,-80,55)
print('平均值=',average(data2))
此程序提示找不到模块NumberError,请问怎么处理?谢谢 展开
def average(data):
sum=0
for i in data:
if i<0:
raise NumberError(str(i))
sum+=i
return sum/len(data)
if __name__=='__main__':
data1=(44,78,80,55)
print('平均值=',average(data1))
data2=(44,78,90,-80,55)
print('平均值=',average(data2))
此程序提示找不到模块NumberError,请问怎么处理?谢谢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询