第9章 Python標準庫概覽(缺3解答)

2021-09-24 10:58:43 字數 1152 閱讀 8321

0901.使用turtle庫繪製乙個蜂窩狀六邊形。

#0901

from turtle import *

def hexagon(x,y,r):

hideturtle()

speed(10)

penup()

goto(x,y)

pendown()

begin_fill()

color('red','yellow')

circle(r,steps=6)

end_fill()

r = eval(input())#輸入半徑

setup(500,500,200,200)

r = pow(3,0.5)*r

hexagon(0,0,r)

hexagon(-r,0,r)

hexagon(r,0,r)

hexagon(-r/2,r*1.5,r)

hexagon(r/2,r*1.5,r)

hexagon(-r/2,-r*1.5,r)

hexagon(r/2,-r*1.5,r)

done()

輸入40的結果:

0902.使用turtle庫繪製一朵玫瑰花。

#本題可參考其他人的部落格,如:

0903.使用turtle庫繪製乙個顏色圖譜。

0904.利用random庫生成乙個包含10個0~100之間隨機整數的列表。

#0904

from random import *

nl =

while len(nl) <= 10:

print(nl)

0905.利用time庫將當前日期轉化成類似「sunday, 8.january 2017 11:03pm」的格式。

#0905

from time import *

lc = localtime()

ft = strftime("%a, %d.%b %y %h:%m%p",lc)

print(ft)

Python標準庫概覽

python標準庫通常被稱為 自帶的電池 自然地提供了廣泛的功能,涵蓋了大概200個左右的包與模組。不斷有高質量的包或模組被開發出來,極大的豐富了標準庫。但有些模組放在標準庫中很難去維護,比如 berkeley db 模組,其被清理出標準庫進行單獨維護。還有一些庫,比如pyparsing 建立分析器...

Python基礎 標準庫概覽 22

1.正規表示式庫re 簡單的例項 import re defre test 函式的定義中,可以看出返回的是乙個匹配物件,它單獨使用就沒有任何意義,需要和findall search match 搭配使用,以match 舉例。c cat p re.compile c u p.match c print...

第5章 標準I O庫

當開啟乙個流時,標準i o函式fopen返回乙個指向file物件的指標。該物件通常是乙個結構,它包含了標準i o庫為管理該流所需要的所有資訊,包括 用於實現i o的檔案描述符 指向用於該流緩衝區的指標 緩衝區的長度 當前在緩衝區中的字元數以及出錯標誌等等。應用程式沒有必要檢驗file物件。對乙個程序...