Python 保留小数位

https://www.luogu.org/problemnew/show/P1422

1.round()内置方法

a = int(input())
sum = 0
if(a >= 401):
  sum += (a-400)*0.5663
  a = 400
if(a >= 151):
  sum += (a-150)*0.4663
  a = 150
sum += a*0.4463

print(round(sum, 1))

2.%f

a = int(input())
sum = 0
if(a >= 401):
  sum += (a-400)*0.5663
  a = 400
if(a >= 151):
  sum += (a-150)*0.4663
  a = 150
sum += a*0.4463

print(("%.1f" % sum))

 

你可能感兴趣的:(Python,洛谷)