五个基本函数算法
准备阶段
import random
from functools import reduce
from collections import Iterable
test=list(range(11))
isinstance(test,Iterable)
max()
def max_count(l:list) -> int:
max_num=l[0]
for i in l:
if max_num < i:
max_num=i
return max_num
min()
def min_count(l:list) -> int:
min_num=l[0]
for i in l:
if min_num > i:
min_num=i
return min_num
sum()
def sum_count(l:list) -> int:
sum_num=0
for i in l:
sum_num+=i
return sum_num
count()
def count_len(l:list) -> int:
len_num=0
for i in l:
len_num+=1
return len_num
avg()
def ave_count(l:list) -> int:
sum_num=0
for i in l:
sum_num+=i
return sum_num/count_len(l)