第一章
实例1.1斐波那契数列计算
1 #CalFibonacci.py 2 a,b=0,1 3 while a<1000: 4 print(a,end=‘,‘) 5 a,b=b,a+b
实例1.2 圆面积的计算
1 #CalCircleArea.py 2 r=25 3 area=3.1415*r*r 4 print(area) 5 print("{:.2f}".format(area))
实例1.3绘制五角红星
1 #DrawStar.py 2 from turtle import* 3 color(‘red‘,‘red‘) 4 begin_fill() 5 for i in range(5): 6 fd(200) 7 rt(144) 8 end_fill() 9 done()
实例1.4 程序运行计时
1 #CalRunTime.py 2 import time 3 limit=10*1000*1000 4 start=time.perf_counter() 5 while True: 6 limit-=1 7 if limit<=0: 8 break 9 delta=time.perf_counter()-start 10 print("程序运行时间是:{}秒。".format(delta))
实例1.5绘制七彩圆圈
1 #DrawSevenColorfulCircles.py 2 import turtle 3 colors=[‘red‘,‘orange‘,‘yellow‘,‘green‘,‘blue‘,‘indigo‘,‘purple‘] 4 for i in range(7): 5 c=colors[i] 6 turtle.color(c,c) 7 turtle.begin_fill() 8 turtle.rt(360/7) 9 turtle.circle(50) 10 turtle.end_fill() 11 turtle.done()
原文:https://www.cnblogs.com/laocm/p/12380572.html