banner

© 2004-21 ict4u.net

List Arithmetic Code

The code snippet below show how to use built in functions to calculate the Max, Min and Number of items

# Date:
# Purpose: Demo list arithmetic - Using built in functions

# initialise the list
numberList = [45, 154, 48, 14, 7, 39, 189, 123]

# Use built-in functions
maxNumber = max(numberList)
minNumber = min(numberList)
sumNumber = sum(numberList)
countNumber = len(numberList)


print(f"Numbers in list:{numberList}\n")

print(f"Maximum:{maxNumber}\nMinimum:{minNumber}\nItems in list:{countNumber}\nSum of Numbers:{sumNumber}\n")