⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiple_return_values.py

📁 python编程很好的入门材料,包括讲义和源码.
💻 PY
字号:
#-------------------------------------------------------------------------------
# Define a function which takes a list of numbers and returns its average and 
# how many numbers were in the list.
#-------------------------------------------------------------------------------

def average( numberList ):
    numCount = 0
    runningTotal = 0
    
    for n in numberList:
        numCount = numCount + 1
        runningTotal = runningTotal + n

    # Return the average and the number count
    return runningTotal / numCount, numCount


# Test the average() function...

myNumbers = [5.0, 7.0, 8.0, 2.0]

theAverage, numberCount = average( myNumbers )

print "The average of the list is " + str( theAverage ) + "."
print "The list contained " + str( numberCount ) + " numbers."

raw_input( "\nPress Enter to exit..." )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -