题解 | #取近似值#

取近似值

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

def approximate_integer(value):
    # 将小数点后的部分提取出来
    decimal = value - int(value)
    
    # 如果小数点后的数值大于等于 0.5,则向上取整
    if decimal >= 0.5:
        return int(value) + 1
    else:
        return int(value)

# 获取用户输入
input_value = float(input())

# 调用函数并输出结果
approximated_integer = approximate_integer(input_value)
print(f"{approximated_integer}")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务