【发布时间】:2014-11-22 17:45:03
【问题描述】:
我的代码目前有问题。该程序工作正常,但由于某种原因,当我输入所有正数时,我收到最后一个函数的错误。最后一个函数是从列表中删除所有负数。
i=0
numList = []
x = int(input("Please enter number from -9999 to end:"))
while x > -9999:
i = i + 1
numList.insert(i,x)
x = int(input("Please enter number from -9999 to end:"))
if x == -9999:
print("The list of numbers entered:",(numList))
newList = numList[:]
secList = numList[:]
def posNumAvg(newList):
for e in newList[:]:
if e < 0:
newList.remove(e)
def negNumAvg(secList):
for y in secList[:]:
if y > 0:
secList.remove(y)
posNumAvg(newList)
negNumAvg(secList)
mydict = {'AvgPositive':(sum(newList)//len(newList)),'AvgNonPos': (sum(secList)//len(secList)),'AvgAllNum':(sum(numList)//len(numList))}
print("The dictionary with averages is:",mydict)
【问题讨论】:
-
你遇到了什么错误?
-
那么程序不能正常工作:)
标签: python list loops python-3.x dictionary