data = input() nums = data.split(",") nums = [float(num) for num in nums] avg = sum(nums)/len(nums) max_num = max(nums) min_num = min(nums) print("{:.2f} {} {}".format(avg, max_num, min_num)) sorted_nums = sorted(nums, reverse=True) print(" ".join([str(num) for num in sorted_nums]))这个代码在输出的时候会增加数据精度,比如输入1,2 它会在输出中变成1.0,2.0,请你改成输出精度不会变的那种,其余不变
时间: 2023-06-07 13:09:16 浏览: 279
nums:nums(3, 6) => [3, 4, 5, 6]
好的,我可以帮您修改代码,修改后的代码如下:
data = input()
nums = data.split(",")
nums = [float(num) for num in nums]
avg = "{:.2f}".format(sum(nums)/len(nums))
max_num = "{:.2f}".format(max(nums))
min_num = "{:.2f}".format(min(nums))
print("{} {} {}".format(avg, max_num, min_num))
sorted_nums = sorted(nums, reverse=True)
print(" ".join([str("{:.2f}".format(num)) for num in sorted_nums]))
阅读全文