VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > python爬虫 >
  • 教你用Python画了一棵圣诞树

作者:曾亲桂林
转载自https://blog.csdn.net/

分享给大家一篇文章,教你怎样用Python画了一棵圣诞树,快来学习。

 

如何用Python画一个圣诞树呢?

最简单:


  1.  
    height = 5
  2.  
  3.  
    stars = 1
  4.  
    for i in range(height):
  5.  
    print((' ' * (height - i)) + ('*' * stars))
  6.  
    stars += 2
  7.  
    print((' ' * height) + '|')

效果:

哈哈哈哈,总有一种骗了大家的感觉。

其实本文是想介绍Turtle库来画圣诞树。


  1.  
    import turtle
  2.  
  3.  
    screen = turtle.Screen()
  4.  
    screen.setup(375, 700)
  5.  
     
  6.  
  7.  
    circle = turtle.Turtle()
  8.  
    circle.shape('circle')
  9.  
    circle.color('red')
  10.  
    circle.speed('fastest')
  11.  
    circle.up()
  12.  
  13.  
    square = turtle.Turtle()
  14.  
    square.shape('square')
  15.  
    square.color('green')
  16.  
    square.speed('fastest')
  17.  
    square.up()
  18.  
  19.  
    circle.goto(0, 280)
  20.  
    circle.stamp()
  21.  
  22.  
    k = 0
  23.  
    for i in range(1, 13):
  24.  
    y = 30 * i
  25.  
    for j in range(i - k):
  26.  
    x = 30 * j
  27.  
    square.goto(x, -y + 280)
  28.  
    square.stamp()
  29.  
    square.goto(-x, -y + 280)
  30.  
    square.stamp()
  31.  
  32.  
    if i % 4 == 0:
  33.  
    x = 30 * (j + 1)
  34.  
    circle.color('red')
  35.  
    circle.goto(-x, -y + 280)
  36.  
    circle.stamp()
  37.  
    circle.goto(x, -y + 280)
  38.  
    circle.stamp()
  39.  
    k += 3
  40.  
  41.  
    if i % 4 == 3:
  42.  
    x = 30 * (j + 1)
  43.  
    circle.color('yellow')
  44.  
    circle.goto(-x, -y + 280)
  45.  
    circle.stamp()
  46.  
    circle.goto(x, -y + 280)
  47.  
    circle.stamp()
  48.  
  49.  
    square.color('brown')
  50.  
    for i in range(13, 17):
  51.  
    y = 30 * i
  52. nodejs爬虫
  53. Python正则表达式完全指南
  54. 爬取豆瓣Top250图书数据
  55. shp 地图文件批量添加字段
  56. 爬虫小试牛刀(爬取学校通知公告)
  57. 【python基础】函数-初识函数
  58. 【python基础】函数-返回值
  59. HTTP请求:requests模块基础使用必知必会
  60. Python初学者友好丨详解参数传递类型
  61. 如何有效管理爬虫流量?
  62. 2个场景实例讲解GaussDB(DWS)基表统计信息估
  63. 常用的 SQL Server 关键字及其含义
  64. 动手分析SQL Server中的事务中使用的锁
  65. openGauss内核分析:SQL by pass & 经典执行
  66. 一招教你如何高效批量导入与更新数据
  67. 天天写SQL,这些神奇的特性你知道吗?
  68. openGauss内核分析:执行计划生成
  69. [IM002]Navicat ODBC驱动器管理器 未发现数据
  70. 初入Sql Server 之 存储过程的简单使用
  71. SQL Server -- 解决存储过程传入参数作为s
  72. JavaScript判断两个数组相等的四类方法
  73. js如何操作video标签
  74. React实战--利用甘特图和看板,强化Paas平
  75. 【记录】正则替换的偏方
  76. 前端下载 Blob 类型整理
  77. 抽象语法树AST必知必会
  78. 关于JS定时器的整理
  79. JS中使用Promise.all控制所有的异步请求都完
  80. js中字符串的方法
  81. import-local执行流程与node模块路径解析流程

相关教程