python端午节代码
时间: 2023-11-16 20:58:49 浏览: 267
Python 端午节代码可以使用 turtle 库来画一个粽子,代码如下:
import turtle
# 画粽子
def draw_zongzi():
turtle.penup()
turtle.goto(-50, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color("green")
turtle.circle(50, steps=3)
turtle.end_fill()
turtle.penup()
turtle.goto(-25, -50)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.circle(25)
turtle.end_fill()
turtle.penup()
turtle.goto(-10, -40)
turtle.pendown()
turtle.begin_fill()
turtle.color("green")
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, -20)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
# 写祝福语
def write_blessing():
turtle.penup()
turtle.goto(0, -100)
turtle.write("祝大家端午安康", move=False, align="center", font=("Comic Sans", 18, "bold"))
# 主函数
def main():
turtle.speed(0)
draw_zongzi()
write_blessing()
turtle.done()
if __name__ == '__main__':
main()
此外,还可以使用 print() 函数来输出祝福语,代码如下:
print("祝大家2021年端午节快乐!")
阅读全文