取近似值[Python]
取近似值
http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a
解题思路:
- 取出小数点后一位数字: 小数点后一位乘10,接着除10取余数
- 判断与5的大小关系,进行操作即可
num = input() num = float(num) * 10 remainder = num % 10 if remainder >= 5: print(int(num/10) + 1) else: print(int(num/10))