python入門高階練習之Turtle庫學習二

2021-10-03 19:47:32 字數 1626 閱讀 7555

目錄

python入門高階練習之turtle庫與random函式

turtle庫是python語言中乙個很流行的繪製影象的函式庫。

1) turtle.pensize():設定畫筆的寬度;

2) turtle.pencolor():沒有引數傳入,返回當前畫筆顏色,傳入引數設定畫筆顏色,可以是字串如"green", "red",也可以是rgb 3元組。

3) turtle.speed(speed):設定畫筆移動速度,畫筆繪製的速度範圍[0,10]整數,數字越大越快。

import turtle as t

t.pensize(5) #設定畫筆的寬度

t.hideturtle() #隱藏畫筆

t.colormode(255)

t.color((255,155,192),"pink")

t.setup(840,500) #起始位置

t.speed(8) #設定畫筆移動速度

t.pu()            #畫筆抬起 penup

t.goto(-100,100)

t.pd() #畫筆按下 pendown

t.seth(30) #設定朝向 30度

t.pu()#畫筆抬起 penup

t.goto(-100,100)

t.pd()#畫筆按下 pendown

t.begin_fill()

t.seth(-10)#設定方向

t.fillcolor('yellow')

t.circle(20)

t.end_fill()

t.begin_fill()

t.seth(10)

t.fillcolor('black')

t.circle(10)

t.end_fill()

t.pu()#畫筆抬起 penup

t.goto(-200,100)

t.pd()#畫筆按下 pendown

t.begin_fill()

t.seth(-10)#設定方向

t.fillcolor('yellow')

t.circle(20)

t.end_fill()

t.begin_fill()

t.seth(10)

t.fillcolor('black')

t.circle(10)

t.end_fill()

t.pu()#畫筆抬起 penup

t.goto(-180,50)

t.pd()#畫筆按下 pendown

t.circle(-60, 60) # 半圓

python 高階學習之5 入門練習題

分別使用while 和for 建立乙個迴圈 a 寫乙個while 迴圈,輸出整數從0 到10。要確保是從0 到10,而不是從0 到9 或 從1 到10 b 做同 a 一樣的事,不過這次使用 range 內建函式。a i 0 while i 11 print i i 1 b for i in rang...

Python練習 高階函式

當乙個函式的引數,傳的是另乙個函式的時候,這樣的函式就是高階函式 變數可以指向函式,如果乙個變數指向了乙個函式,那麼,可通過該變數來呼叫這個函式 ap 函式接收兩個引數,乙個是函式,乙個是iterable,map將傳入的函式依次作用到序列的每個元素,並把結果作為新的iterator返回。def f ...

python練習 高階篇)

1 求1 2 3 4 5 99的和 count 1 s1 0 s2 0 while count 100 if count 2 0 s1 count else s2 count count 1 s s1 s2 print s 2 用python編寫程式,輸入一年份,判斷該年份是否是閏年並輸出結果 注 ...