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


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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM