代码
import math
a1 = 23
a2 = 2**3
a3 = 5+25
a4 = -4--4--4
a5 = 6/2
a6 = 7%2
a7 = 5.0+2.0
a8 = 4.0-3-3
a9 = 6.0%2
a10 = float(4)
a11 = int(4)
a12 = int(5.3)
a13 = float(int(5.3))
a14 = int(-5.3)
a15 = float(7)/4
a16 = type(4)
a17 = type(4.0)
a18 = math.ceil(5.3)
a19 = math.floor(8.6)
a20 = math.pow(2,3)
a21 = math.sin(math.pi/2)
a22 = math.sqrt(4)
a23 = 6.0%2
a24 = math.log10(1000)
a25 = math.fmod(145,23)
a26 = math.radians(30)
a27 = 6.0/2
a = 1
while True:
to_print = "a" + str(a)
try:
print(eval(to_print))
except:
break
a +=1
运行结果:
Python 3.5.3 (default, Apr 22 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "copyright", "credits" or "license()" for more information.
=================== RESTART: /home/shiyanlou/Code/math.py ===================
6
8
15
4
3.0
1
7.0
-2.0
0.0
4.0
4
-5
5.0
-5
1.75
6
8
8.0
1.0
2.0
0.0
3.0
7.0
0.5235987755982988
3.0
表达式 计算值 计算结果依据
23 6 23=6
2*3 8 222=8
5+25 15 5+2*5=15
-4--4--4 4 -4+4+4=4
6/2 3.0 除法将保留浮点数
7%2 1 7除2余1
-8%3 -2 python中向负无穷求整
5.0+2.0 7.0 浮点数相加结果为浮点数
4.0-3-3 -1.0 运算过程中有浮点数结果为浮点数
6.0/2 3.0 同上
6.0%2 0.0 同上
float(4) 4.0 将4转化为浮点数4.0
int(4) 4
int(5.3) 5
float(int(5.3)) 5.0
int(-5.3) -5
float(7)/4 1.75
type(4)
type(4.0)
math.ceil(5.3) 6
math.floor(8.6) 8
math.pow(2,3) 8.0
math.sin(math.pi/2) 1.0
math.sqrt(4) 2.0
6.0%2 0.0
math.log10(1000) 3.0
math.fmod(145,23) 7.0
math.radians(30) 0.5235987755982988