码迷,mamicode.com
首页 > 编程语言 > 详细

计算机国考二级Python教材实例1

时间:2020-02-28 22:49:28      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:运行   span   for   斐波那契   int   数列   运行时   bsp   斐波那契数列   

第一章

实例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()

 

计算机国考二级Python教材实例1

标签:运行   span   for   斐波那契   int   数列   运行时   bsp   斐波那契数列   

原文地址:https://www.cnblogs.com/laocm/p/12380572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!