#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'N个数字的平均值'
N = 3
sum = 0
count = 0
while count < N:
num = float(input('number:'))
sum = num + sum
count += 1
average = sum / N
print(type(sum))
print("N: %s, sum: %d ,average: %.2f" % (N, sum, average))
print("N:{}, sum:{} ,average:{:.2f}".format(N, sum, average))
# print("N:{}, sum:{:d} ,average:{:.2f}".format(N, sum, average))
最后注释掉的那一行报错,ValueError: Unknown format code 'b' for object of type 'float'
我想把sum,例如60.0这样的浮点数,整数输出
试下这个