python打印楼梯和笑脸_用Python的Turtle库打印楼梯,并打印笑脸:)

import turtle

#画矩形立方体

def draw_cube(i):

turtle.begin_fill()

turtle.color("yellow")

turtle.goto(i,i*3)

turtle.goto(100+i,i*3)

turtle.goto(100+i,20+i*3)

turtle.goto(i,20+i*3)

turtle.goto(i,i*3)

turtle.end_fill()

turtle.penup()

turtle.goto(i,20+i*3)

turtle.pendown()

turtle.goto(10+i,30+i*3)

turtle.goto(110+i,30+i*3)

turtle.goto(110+i,10+i*3)

turtle.goto(100+i,i*3)

turtle.penup()

turtle.goto(100+i,20+i*3)

turtle.pendown()

turtle.goto(110+i,30+i*3)

#画笑脸

def draw_smile_face(x,y):

turtle.goto(x+50,y)

turtle.pensize(1.5)

#脸部

turtle.circle(20)

turtle.penup()

#眼睛

turtle.goto(x+40,y+20)

turtle.pendown()

turtle.begin_fill()

turtle.color("yellow")

turtle.circle(3)

turtle.end_fill()

turtle.penup()

turtle.goto(x+60,y+20)

turtle.pendown()

turtle.begin_fill()

turtle.color("yellow")

turtle.circle(3)

turtle.end_fill()

turtle.penup()

#嘴巴

turtle.goto(x+45,y+10)

turtle.pendown()

turtle.right(90)

turtle.pensize(2)

turtle.circle(5,180)

def main():

turtle.speed(2)

for i in range(0,100,10):

draw_cube(i)

draw_smile_face(100,300)

turtle.hideturtle()

main()

效果图如下:

cdb056463c96ef9a9558ef833bd0f1a6.png

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值