我的Python學習之路 5

2021-10-25 12:40:36 字數 3759 閱讀 7727

1.學習python函式的定義和使用,掌握並了解遞迴函式中基例(遞迴出口)和鏈條(遞迴體)的定義

2.安裝pyinstaller庫並將源**(.py)打包為可執行程式(.exe)

3.根據之前所學的time庫和turtle庫,結合函式內容編寫七段數碼管例項並打包

4.了解科赫曲線的實現機理,嘗試編寫**實現科赫雪花效果

最後即可生成帶圖示的exe檔案

2.然後執行下圖的命令轉到原始碼所在的目錄:

3.接著執行下圖的命令來打包生成我們想要的.exe可執行檔案:

4.等待一段時間後,控制台最後一句出現successfully字眼的語句時打包成功,在源**所在的目錄中會出現3個資料夾,如下圖所示,其中_pycache_和build資料夾可以自行刪除,dist資料夾內就是我們需要的.exe可執行檔案!

#七段數碼管.py

import turtle as t

import time

defdrawgap()

:#數碼管的間隔

t.penup(

) t.fd(5)

defdrawline

(draw)

:#繪製單段數碼管

drawgap(

) t.pendown(

)if draw else t.penup(

) t.fd(40)

drawgap(

) t.right(90)

defdrawdigit

(digit)

:#根據引數digit繪製七段數碼管

drawline(

true

)if digit in[2

,3,4

,5,6

,8,9

]else drawline(

false

) drawline(

true

)if digit in[0

,1,3

,4,5

,6,7

,8,9

]else drawline(

false

) drawline(

true

)if digit in[0

,2,3

,5,6

,8,9

]else drawline(

false

) drawline(

true

)if digit in[0

,2,6

,8]else drawline(

false

) t.left(90)

drawline(

true

)if digit in[0

,4,5

,6,8

,9]else drawline(

false

) drawline(

true

)if digit in[0

,2,3

,5,6

,7,8

,9]else drawline(

false

) drawline(

true

)if digit in[0

,1,2

,3,4

,7,8

,9]else drawline(

false

) t.left(

180)

t.penup(

)#為繪製後續數字確定位置

t.fd(20)

defdrawdate

(date)

:#獲取要輸出的時間,date為時間

t.pencolor(

"red"

)for i in date:

if i ==

'年':

t.write(

'年', font =

("幼圓",18

,"normal"))

t.pencolor(

"green"

) t.fd(40)

elif i ==

'月':

t.write(

'月', font =

("幼圓",18

,"normal"))

t.pencolor(

"blue"

) t.fd(40)

elif i ==

'日':

t.write(

'日', font =

("幼圓",18

,"normal"))

else

: drawdigit(

eval

(i))

defmain()

:#主函式

t.setup(

800,

350)

t.penup(

) t.fd(

-300

) t.pensize(5)

drawdate(time.strftime(

'%y年%m月%d日'

3#階數

koch(

400, level)

#3階科赫曲線

t.right(

120)

koch(

400, level)

t.right(

120)

koch(

400, level)

t.hideturtle(

)#隱藏海龜

t.done(

)main(

)

我的python學習之路

初識python 獲取url位址解析url原始碼提取原始碼中的需要資訊使用re beautifulsoup urllib.request等常用庫寫入txt excel等等。format string string to convert 其中 format string為格式標記字串,形式為 cdoe...

我的python學習之路

python tutorial 入門指南 runoob.com python 3.7.4 官方文件 w3cschool python3手冊文件 python3標準庫 主題 像科學家一樣思考pytho 2.python web相關 django官網 劉江的部落格教程 django 3.爬蟲框架 scr...

python學習之路(5)

計算機之所以能做很多自動化的任務,因為它可以自己做條件判斷。比如,輸入使用者年齡,根據年齡列印不同的內容,在python程式中,用if語句實現 age 20 if age 18 print your age is age,s 歲 your age is 20 歲 根據python的縮排規則,如果if...