我得到"类型错误:'NoneType’对象不是可迭代的"上线"公司名称,monthAverage,costPerTon,TOTALCOST = displayCost(公司名称,monthAverage,costPerTon,TOTALCOST)",我不能为我的生命弄清楚为什么.
抱歉,我似乎无法正确格式化...
4-25-11最终项目,全球垃圾计划
主要功能
def main():
#intialize variables
endProgram = 'no'
companyName = 'NONAME'
#call to input company name
companyName = inputName(companyName)
#start 'end program' while loop
while endProgram == 'no':
#initializes variables
companyName = 'NONAME'
monthAverage = 0
costPerTon = 0
totalCost = 0
yearTotal = 0
#call to input company name
companyName = inputName(companyName)
#call to get the tonnage
yearTotal, monthAverage = getTonnage(yearTotal, monthAverage)
#call to calculate the cost
monthAverage, costPerTon, totalCost, yearTotal = calculateCost(monthAverage, costPerTon, totalCost, yearTotal)
#call to display the cost
companyName, monthAverage, costPerTon, totalCost = displayCost(companyName, monthAverage, costPerTon, totalCost)
endProgram = raw_input('Do you want to end the program? (enter yes or no)')
Run Code Online (Sandbox Code Playgroud)
得到公司名称
def inputName(companyName):
companyName = raw_input('What is the name of your company? ')
return companyName
Run Code Online (Sandbox Code Playgroud)
获得吨位
def getTonnage(yearTotal, monthAverage):
yearTotal = input('How many tons of garbage are you dumping this year? ')
monthAverage = yearTotal / 12
return yearTotal, monthAverage
Run Code Online (Sandbox Code Playgroud)
计算通话
def calculateCost(monthAverage, costPerTon, totalCost, yearTotal):
if monthAverage > 100:
costPerTon = 7000
elif monthAverage > 50:
costPerTon = 6500
elif monthAverage > 20:
costPerTon = 5500
else:
costPerTon = 4500
totalCost = costPerTon * yearTotal
return monthAverage, costPerTon, totalCost, yearTotal
Run Code Online (Sandbox Code Playgroud)
打印成本
def displayCost(companyName, monthAverage, costPerTon, totalCost):
print 'Dear',companyName
print 'The average tonnage per month is ', monthAverage
print 'The cost per ton is $',costPerTon
print 'The total the is the cost per ton times total tons $',totalCost
Run Code Online (Sandbox Code Playgroud)
主要运行
main()
Run Code Online (Sandbox Code Playgroud)
您尝试将displayCost的返回值解压缩为4个变量,但displayCost不返回任何内容.因为每个函数调用都在Python中返回一些东西(或引发异常),所以返回None.然后无法解压缩.
你可能想要改变:
companyName, monthAverage, costPerTon, totalCost = displayCost(companyName, monthAverage, costPerTon, totalCost)
Run Code Online (Sandbox Code Playgroud)
至:
displayCost(companyName, monthAverage, costPerTon, totalCost)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11227 次 |
| 最近记录: |