【#第一文档网# 导语】以下是®第一文档网的小编为您整理的《Python 实验1 布尔表达式等》,欢迎阅读!
实验1 【实验目的】 1.掌握4种数字类型的概念和使用 2.掌握和类型数字在计算机中的表示方法 3.掌握Python数学库进行数值计算 【实验内容】 1. 写出下面的结果,并分析原因。 要求:写出答案,再在Python command line上运行验证。 (1) 进制转换,把以下进制转换成十进制: 0XABC= 2748 0O7653= 4011 0B11101010111101= 15037 (2) 数值转换: a=10,b=3,a/b=__3__,原因是什么___10除以3商3____ a=10.0,b=3,a/b=_3.33333333333335_,原因是什么_浮点数与整数相除等于浮点数__ 在Python中,整数的取值范围是__32位系统:2^31-1,64位系统:2^63-1,其后进入高精度计算__ 0.00045的科学记数法是____4.5e-4____ a=5.5,int(a)=___5____,b=5.3,int(b)=__5_ 虚数c=4+3j,type(c)=_‘complex’>_,c.real=_4 ,c.imag=__3j__ d=10,float(d)=__10.0__, f=3.5,complex(f)=__3.5+0j__ g=3+4j,float(g)结果是什么__错误,无法转换浮点数和复数__
(3) 数值计算:
a=10,b=4,求下面的结果:
a+b=__14_,a-b=__6_,a*b=__40_,a/d=_2__
a//b=_2_,a%b=___2__,divmod(a,b)=____(2,2)____ pow(a,b)=__10000__,x**y=____10000____
c=20,d=5,5cd结果是什么__错误__,为什么_5cd相当于变量,5*c*d才是表达式_
2. 布尔表达式练习
要求:写出答案,再在Python command line上运行验证。 Answer:
1) 1 == 1 and 2 == 1, False 2) "test" == "test", True 3) 1 == 1 or 2 != 1 True 4) True and 1 == 1 True 5) False and 0 != 0 False 6) True or 1 == 1 True 7) "test" == "testing" False 8) 1 != 0 and 2 == 1 False 9) "test" != "testing" True 10) "test" == 1 False 11) not (True and False) True 12) not (1 == 1 and 0 != 1) False 13) not (10 == 1 or 1000 == 1000) False 14) not (1 != 10 or 3 == 4) False
15) not ("testing" == "testing" and "Zed" == "Cool Guy") True 16) 1 == 1 and not ("testing" == 1 or 1 == 0) True 17) "chunky" == "bacon" and not (3 == 4 or 3 == 3) False
18) 3 == 3 and not ("testing" == "testing" or "Python" == "Fun") False
3. 编写程序,输入球体半径,计算出球的体积和表面积,并输出结果。 (根据书本示例程序1:温度转换)
第一步:分析问题:可以通过公式:球的表面积=4π*R*R, 球的体积=(4/3)π*R*R*R来获得。 第二步:设计算法: 输入半径R
计算球表面积与体积 输出结果 第三步:编写程序
创建一个新的文档,命名为 #设置常量π
pi=3.1415927
#输入半径R的值
R=input("Please enter R:") #计算表面积与体积
S=4*π*R*R
V=(4.0/3)*π*R*R*R #v=(4/3)* π*R*R*R行不行,为什么? #打印结果
Print “S=”,S,”\nV=”,V
Answer:
pi=3.1415927
R=input("Enter the R:") S=4*pi*R*R V=(4.0/3)*pi*R*R*R print "S=",S print "V=",V
第四步 运行程序: 点击菜单“run”“Run Module F5”,可在窗口界面中查看运行结果 回车直接显示
Enter the R:1 (输入1) S= 3.1415927
V= 4.18879026667
本文来源:https://www.dywdw.cn/d7eec885a0c7aa00b52acfc789eb172ded63998d.html