题解 | #取近似值#

取近似值

https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a

思路1:使用加0.5的方法

a=float(input())

b=int(a+0.5)

print(b)

思路2:使用math库里的ceil和floor函数

form math import ceil,floor

def FJ(n):

a=ceil(n)-n

if a<=0.5:

return(ceil(n))

else:

return(floor(n))

b=float(input())

print(FJ(b))

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务