输入n科成绩(浮点数表示),统计其中的最高分,最低分以及平均分。
数据范围:
, 成绩使用百分制且不可能出现负数
两行,
第1行,正整数n(1≤n≤100)
第2行,n科成绩(范围0.0~100.0),用空格分隔。
输出一行,三个浮点数,分别表示,最高分,最低分以及平均分(小数点后保留2位),用空格分隔。
5 99.5 100.0 22.0 60.0 88.5
100.00 22.00 74.00
n = int(input())
s = list(map(float, input().split()))
print(f'{max(s):.2f} {min(s):.2f} {sum(s)/len(s):.2f}') num=int(input())
scores=input().split()
sume = 0
for i in range(num):
sume=sume+float(scores[i])
for j in range(num):
scores[j]=float(scores[j])
average=sume/num
print("%.2f"%max(scores),"%.2f"%min(scores),"%.2f"%average) class Gard():
def print_gard(self):
# 第一行输入人数
num = int(input())
gard = input()
list_gard = gard.split(' ')
# print(list_gard)
sum = 0
# 把列表的第一个元素赋值给max和min必须是元素,不然是0的话会结果有误
max = float(list_gard[0])
min = float(list_gard[0])
for i in list_gard:
# 遍历找出最大的
if max > float(i):
pass
else:
max = float(i)
# 同理遍历除最小的
if min < float(i):
pass
else:
min = float(i)
sum = float(i) + sum
# 平均数等于总数除以人数
avg = sum / num
# 保留两位小数
print('%.2f'%max,'%.2f'%min,'%.2f'%avg)
if __name__ == '__main__':
Gard().print_gard() n = int(input())
scores = input().split()
num = [float(i) for i in scores]
print ('%.2f'%max(num), '%.2f'%min(num), '%.2f'%(sum(num)/n))
def max_function(a):
max_number = float(a[0])
for item in a:
if float(item) > float(max_number):
max_number = item
return max_number
def min_function(b):
min_number = float(b[0])
for item in b:
if float(item) < float(min_number):
min_number = item
return min_number
def ave_function(c):
sum_result = 0.00
for item in c:
sum_result += float(item)
average_number = float(sum_result / len(c))
return average_number
count_number = input("")
X = input().split()
result_high = float(max_function(X))
result_low = float(min_function(X))
result_ave = float(ave_function(X))
print("%.2f %.2f %.2f" % (result_high,result_low,result_ave))
#格式化字符串输出