將字符串中的每個數都抽取出來,然后統計所有數的個數並求和。
輸入格式:
一行字符串,字符串中的數之間用1個空格或者多個空格分隔。
輸出格式:
第1行:輸出數的個數。
第2行:求和的結果,保留3位小數。
輸入樣例:
2.1234 2.1 3 4 5 6
輸出樣例:
6 22.223
代碼:
a = input() list = a.split(" ") total = 0 count = 0 for i in range(0, len(list)): if list[i] == '': continue total = total + float(list[i]) count += 1 print(count) print(round(total,3))