function_return_value.py
来自「python编程很好的入门材料,包括讲义和源码.」· Python 代码 · 共 26 行
PY
26 行
#-------------------------------------------------------------------------------
# Define a function which takes a list of numbers and returns its average.
#-------------------------------------------------------------------------------
def average( numberList ):
numCount = 0
runningTotal = 0
for n in numberList:
numCount = numCount + 1
runningTotal = runningTotal + n
# Return the average
return runningTotal / numCount
# Test the average() function...
myNumbers = [5.0, 7.0, 8.0, 2.0]
theAverage = average( myNumbers )
print "The average of the list is " + str( theAverage ) + "."
raw_input( "\nPress Enter to exit..." )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?