1. 程式人生 > >離python二級考還有十幾天,嚇的我趕緊買了本python教程

離python二級考還有十幾天,嚇的我趕緊買了本python教程

seve 時間 imp python ORC 道理 import 斐波那契數列 斐波那契數

不多說,前面粗略的看一下,直接進入實例部分,敲代碼實踐才是硬道理

實例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教程