日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python實現畫桃心表白_python

作者:amcomputer ? 更新時間: 2022-07-04 編程語言

python畫桃心表白

python用turtle畫簡單圖案比較方便,大一學python的turtle模塊時,記得要畫各種圖案,如國旗,桃心等等圖案,期末課程設計時有可能還會遇到畫54張撲克牌,當初室友就被迫選了這道題。

有時候程序猿遇到自己悄悄喜歡的女生又不敢表白,那么就用turtle來實現表白吧!!!!!!!

下面是程序

import turtle
import time
def LittleHeart():
    for i in range(200):
        turtle.right(1)
        turtle.forward(2)
isLove=input('你會一直愛她嗎?(Y or N)\n')
 
run =1
while(run):
    if isLove=="Y":
        me=""
        love=""
        if love=='': 
            love=' 草莓 I love you'
        turtle.setup(width=900, height=500)
        turtle.color('red','red')
        turtle.pensize(3)
        turtle.speed(50)
        turtle.up()
        turtle.hideturtle()
        turtle.goto(0,-180)
        turtle.showturtle()
        turtle.down()
        turtle.speed(5)
        turtle.begin_fill()
        turtle.left(140)
        turtle.forward(224)
        LittleHeart()
        turtle.left(120)
        LittleHeart()
        turtle.forward(224)
        turtle.end_fill()
        turtle.pensize(5)
        turtle.up()
        turtle.hideturtle()
        turtle.goto(0,0)
        turtle.showturtle()
        turtle.color('#CD5C5C','blue')
        turtle.write(love,font=('gungsuh',30,),align="center")
        turtle.up()
        turtle.hideturtle()
        if me !='':
            turtle.color('yellow', 'red')
            time.sleep(2)
        turtle.goto(180,-180)
        turtle.showturtle()
        turtle.write(me, font=(20,), align="center", move=True)
        window=turtle.Screen()
        window.exitonclick()
        run =0
 
       
    else:
         print("活該單身一輩子")
         print("!!!!!!!!!再給你一次機會!!!!!!!!")
         isLove=input('你會一直愛她嗎?(Y or N)\n')
         continue

運行結果:

一行Python代碼畫心型

1、畫I組成的心型代碼

print('\n'.join([''.join([('I'[(x-y) % len('I')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))

2、畫Love組成的心型代碼

print('\n'.join([''.join([('Love'[(x-y) % len('Love')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))

3、畫You組成的心型代碼

print('\n'.join([''.join([('You'[(x-y) % len('You')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))

4、畫Raven組成的心型代碼

print('\n'.join([''.join([('Raven'[(x-y) % len('Raven')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))

原文鏈接:https://blog.csdn.net/qq_39463175/article/details/103259009

欄目分類
最近更新