日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

用python输出圣诞树_教你怎样用Python画了一棵圣诞树,赶紧来学习

發布時間:2024/3/13 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用python输出圣诞树_教你怎样用Python画了一棵圣诞树,赶紧来学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文中的文本及圖片來源于互聯網,僅作學習培訓、溝通交流應用,不具備一切商業行為,如有什么問題請立即在線留言以作解決。

下列文章內容來源于IT新手入門

共享給大伙兒一篇文章,教你如何用Python畫了一棵圣誕樹,趕緊來學習培訓。

怎樣用Python畫一個圣誕樹呢?

非常簡單:

height?=?5stars?=?1for?i?in?range(height):????print(('?'?*?(height?-?i))???('*'?*?stars))

stars??=?2print(('?'?*?height)???'|')

實際效果:

哈哈哈哈哈哈,總有一種騙了大伙兒的覺得。

實際上文中是想詳細介紹Turtle庫來畫圣誕樹。

import?turtle

screen?=?turtle.Screen()

screen.setup(375,?700)

circle?=?turtle.Turtle()

circle.shape('circle')

circle.color('red')

circle.speed('fastest')

circle.up()

square?=?turtle.Turtle()

square.shape('square')

square.color('green')

square.speed('fastest')

square.up()

circle.goto(0,?280)

circle.stamp()

k?=?0for?i?in?range(1,?13):

y?=?30?*?i????for?j?in?range(i?-?k):

x?=?30?*?j

square.goto(x,?-y???280)

square.stamp()

square.goto(-x,?-y???280)

square.stamp()????if?i?%?4?==?0:

x?=?30?*?(j???1)

circle.color('red')

circle.goto(-x,?-y???280)

circle.stamp()

circle.goto(x,?-y???280)

circle.stamp()

k??=?3????if?i?%?4?==?3:

x?=?30?*?(j???1)

circle.color('yellow')

circle.goto(-x,?-y???280)

circle.stamp()

circle.goto(x,?-y???280)

circle.stamp()

square.color('brown')for?i?in?range(13,?17):

y?=?30?*?i????for?j?in?range(2):

x?=?30?*?j

square.goto(x,?-y???280)

square.stamp()

square.goto(-x,?-y???280)

square.stamp()

實際效果:

方式二:

import?turtle#?界定圣誕樹的綠葉子涵數def?tree(d,?s):????if?d?<=?0:????????return

turtle.forward(s)

tree(d?-?1,?s?*?.8)

turtle.right(120)

tree(d?-?3,?s?*?.5)

turtle.right(120)

tree(d?-?3,?s?*?.5)

turtle.right(120)

turtle.backward(s)

n?=?100"""?設定制圖速率

'fastest'?:??0

'fast'????:??10

'normal'??:??6

'slow'????:??3

'slowest'?:??1"""turtle.speed('fastest')?#?設定速率turtle.left(90)

turtle.forward(3?*?n)

turtle.color("orange",?"yellow")

turtle.left(126)#?turtle.begin_fill()for?i?in?range(5):

turtle.forward(n?/?5)

turtle.right(144)

turtle.forward(n?/?5)

turtle.left(72)

turtle.end_fill()

turtle.right(126)

turtle.color("dark?green")

turtle.backward(n?*?4.8)#?實行涵數tree(15,?n)

turtle.backward(n?/?5)

實際效果:

總結

以上是生活随笔為你收集整理的用python输出圣诞树_教你怎样用Python画了一棵圣诞树,赶紧来学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。