Python练习册

Practices 1:


说明:

for循环,i取值范围为1-10,不包括11;
sum += 1.0 / i表示 sum = sum + 1.0 / i;
3d表示如果位数不足3位,则用空格补齐;
6.4f表示如果小数后面位数不足4位,则用0补齐,如果整个小数不足 6 位(小数点占 1 位), 整数前用空格补足;
format格式化,i采用3d的格式.而sum采用6.4f的格式; 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

演示:

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

Pracitces 2:文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/


说明:文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

导入math模块;
a、b、c等待用户输入,且转换为整数;
d的值为 运算结果;(1 * 1 - 4 * 5 * 0) = 1
如果d的值小于0,则打印ROOTS are imaginary;
否则
root1= (-1 + 1.0) / (2 * 5)
root2= (-1 - 1.0) / (2 * 5) = -2 / 10 = 0.2 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

演示:

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

Practices 3: 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/


说明:文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

numberofcamera = 3
price = 2
bonus = 200 * 3
commision = 0.02 * 3 * 2
打印bonus,保留2位2小数,整个字符长度为6位
同上 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

演示:

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/python-exercise-test/

Practices 4:

说明:

import math #导入模块
R = 3
PI = 3.141592653589793 #π
circlearea = 3.141592653589793 * 3 * 3 #圆的面积公式 πR²
{:4.10f} 表示整个长度为4位以上,如果长度不够整数前用空格补齐(包括小数点),取小数点后10位

演示:

Practices 5:


说明:

a=0 b=1
当b小于100的时候,循环进行
第一次循环 a = 0 b = 1 且打印b
赋值 a = b = 1
第二次循环 a = 1 b = 1
第N次循环 a = 34 b = 55
第N+1次循环 a = 89 b = 144 不符合条件,跳出循环

print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

演示:

Practices 6:


说明:

print(b, end =' ') 将默认换行符换成空格

演示:

Practices 7:


说明:

演示:

Pracitces 8:


说明:

x = 2.0
n = term = num = 1
n小于或者等于100 循环成立
term = term * x / n = 1 * 2.0 = 2.0
result = result + term = 1.0 + 2.0 =3.0
n = n + 1

演示:

申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!

On this day in past years
May
10
 
Byrd
  • by Published onMay 10, 2019
  • 原文链接:https://note.t4x.org/basic/python-exercise-test/
匿名

Comment

Anonymous

Slide puzzle verification.