#38816: 請問python有什麼解題技巧嗎


jun103010418@gmail.com (駿陳)


a = int(input())
b = list(map(int, input().split()))
ans = sum(b)
c = ans / a
formatted_c = "{:.2f}".format(c)

if formatted_c[-1] == "0":
    print(float(c * 10))

#41119: Re: 請問python有什麼解題技巧嗎


seancai78@gmail.com (風月春秋)


說實話,大多語言沒有內建到第幾位的四捨五入
你要實踐的話就是取三位小數點(乘1000再取餘)
再對那個整數做條列判斷

#42821: Re: 請問python有什麼解題技巧嗎


sam851015@gmail.com (多挖鼻孔有益身心健康)


我的作法是先把答案格式化 f'{ans:.2f}'

然後再對結果 rstrip 多餘的0