我有这样一个程序:
def facilities():
total_rate=vrates=funrate=rates5=0
def food():
#files are used
rates5=0
# calculate the rate and store the total rate in rates5
def recreation():
#files are used
funrate=0
# calculate the rate and store the total rate in funrate
def transport():
#files are used
vrates=0
# calculate the rate and store the total rate in vrates
food()
recreation()
transport()
total_rate=rates5+vrates+funrate
print"The total amount=",total_rate
facilities()
最后,我想计算funrate,vrates和rates5的和。例如:funrate=100,vrates=200,rates5=300,然后total\u rate=600,但是当我运行程序时,它就像总量=0。要么什么都没有,要么total\u rate=0。申报有什么问题吗
实际上,真正的程序是非常长的,所以我缩短了它得到的主要思想。我有嵌套函数作为程序的一部分。 请帮帮我
如果这种方法对您有效,请告诉我:
另一种方法是:
以及针对问题的结构化类解决方案:
您的程序有许多问题:
facilities()
函数不返回任何值food()
、recreation()
和transport()
声明但从未调用funrate
和vrates
变量在内部作用域中定义。结果永远不会返回total_rate=rates5+vrates+funrate
中的{funrate
和vrates
未赋值另外,我很感兴趣的是你是如何成功地运行它来获得任何结果的
相关问题 更多 >
编程相关推荐