随机生成10个数,赋给一维数组,求出一维数组的max、min、求和、平均值,并且改写成一个方法
时间: 2024-05-30 12:16:35 浏览: 96
import random
def array_stats(n):
arr = [random.randint(1, 100) for i in range(n)]
max_num = max(arr)
min_num = min(arr)
total = sum(arr)
avg = total / n
return max_num, min_num, total, avg
max_num, min_num, total, avg = array_stats(10)
print("Max number:", max_num)
print("Min number:", min_num)
print("Total:", total)
print("Average:", avg)
阅读全文