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

离python二级考还有十几天,吓的我赶紧买了本python教程

时间:2019-03-12 19:59:03      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:bre   斐波那契数   时间   框架   绘制   a+b   run   one   start   

不多说,前面粗略的看一下,直接进入实例部分,敲代码实践才是硬道理

实例1 斐波那契数列 

#feibonaqieshulie #这英文我是真的不会,不过拼音也勉强够用
a,b = 0,1
while a<1000:
print(a,end=",")
a,b = b,a+b

实例2 简单圆面积的计算

#Area yuan
r = 20
Area = 3.14
15*(r*r)
print("{:.2f}".format(Area))

实例3 绘制五角星(有点小炫酷)

#DrawStar.py
from turtle import *            #turtle为python制图的一种函数
color(‘red‘,‘red‘)    #color里面前面类似画五角星的笔,后面则是框架画好之后一桶颜料倒上去
begin_fill()
for i in range(5):
fd(200)
rt(144)
end_fill()
done()

实例4 一个程序运行的时间

#calRunTime.py
import time
limit = 10*1000*1000
start = time.perf_counter()
while True:
limit -= 1
if limit <=0:
break
delta = time.perf_counter() - start
print("程序运行的时间是:{}秒".format(delta))

实例5 七彩圆圈

#DrawSevenColorfulCorcles.py
import turtle
colors = [‘red‘,‘orange‘,‘yellow‘,‘green‘,‘blue‘,‘indigo‘,‘purple‘]
for i in range(7):
c=colors[i]
turtle.color(c,c)
turtle.begin_fill()
turtle.rt(360/7)
turtle.circle(50)
turtle.end_fill()
turtle.done()

离python二级考还有十几天,吓的我赶紧买了本python教程

标签:bre   斐波那契数   时间   框架   绘制   a+b   run   one   start   

原文地址:https://www.cnblogs.com/dmsbknxd/p/10519158.html

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