整型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
标签:数据类型,num,取整,print,n1,n2,math,python2
From: https://blog.csdn.net/qq_42547097/article/details/141428341