Python沸羊羊(完整代码)

95 篇文章 127 订阅 ¥29.90 ¥99.00
这篇博客主要介绍了Python中的异常处理,包括文件不存在时的处理和字典操作。在文件操作部分,用户输入文件名,如果文件不存在则创建并写入内容,存在则读取内容。在字典操作部分,用户输入键,如果键不存在则提示重新输入,输入'exit'结束程序。通过try-except结构实现异常处理,确保程序的稳定运行。
摘要由CSDN通过智能技术生成
以下是使用Python的turtle库画沸羊羊的代码: ```python import turtle # 设置画笔初始位置和朝向 turtle.penup() turtle.goto(-100, 100) turtle.pendown() turtle.setheading(-60) # 画出羊的头部和身体 turtle.begin_fill() turtle.circle(50, steps=3) turtle.color('yellow') turtle.end_fill() turtle.begin_fill() turtle.circle(-50, steps=3) turtle.color('white') turtle.end_fill() # 画出羊的脚 turtle.penup() turtle.goto(-60, 0) turtle.pendown() turtle.setheading(-90) turtle.color('black') turtle.begin_fill() turtle.forward(30) turtle.right(90) turtle.forward(10) turtle.right(90) turtle.forward(30) turtle.right(90) turtle.forward(10) turtle.end_fill() turtle.penup() turtle.goto(10, 0) turtle.pendown() turtle.setheading(-90) turtle.color('black') turtle.begin_fill() turtle.forward(30) turtle.right(90) turtle.forward(10) turtle.right(90) turtle.forward(30) turtle.right(90) turtle.forward(10) turtle.end_fill() # 画出羊的耳朵和眼睛 turtle.penup() turtle.goto(-90, 120) turtle.pendown() turtle.setheading(60) turtle.color('white') turtle.begin_fill() turtle.circle(-20, steps=3) turtle.end_fill() turtle.penup() turtle.goto(-85, 130) turtle.pendown() turtle.setheading(0) turtle.color('black') turtle.begin_fill() turtle.circle(-5) turtle.end_fill() turtle.penup() turtle.goto(-60, 120) turtle.pendown() turtle.setheading(120) turtle.color('white') turtle.begin_fill() turtle.circle(-20, steps=3) turtle.end_fill() turtle.penup() turtle.goto(-55, 130) turtle.pendown() turtle.setheading(0) turtle.color('black') turtle.begin_fill() turtle.circle(-5) turtle.end_fill() # 完成画图 turtle.hideturtle() turtle.done() ``` 运行代码后,就可以在turtle窗口里看到画出来的沸羊羊了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Want595

感谢小伙伴的支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值