整型int
input()里面输出的都是字符串类型的,要转换成int类型在进行加减乘除
num = input('请输入一个数字:')
print(type(num))
num = int(num) +10
print(num)
浮点数
产生误差:
采用round四舍五入:
n1 = 0.1
n2 = 0.2
n3 = round(n1+n2,2)
print(n3)
取整操作:向上取整
n1 = 2.1
n2 = 15.256
import math
n4 = math.ceil(n1+n2)
print(n4)
取整操作:向下取整
n1 = 2.1
n2 = 15.256
import math
n4 = math.floor(n1+n2