import math x = float(input()) down = math.floor(x) up = math.ceil(x) if up - x <= x - down: print(up) else: print(down) 对于python中的小数/浮点数,数据类型是float,没有double导入math库,使用math.ceil()完成向上取整,使用math.floor()完成向下取整通过上下取整后与原数的差值进行比较,偏向小于的一方,如果等于选择上取整