用python打印各种图形
短信预约 -IT技能 免费直播动态提醒
#用python打印出直角三角形:
1 #!/usr/bin/env python
2 # coding=utf-8
3 i = 0
4 while i < 5:
5 j = 0
6 while j <= i:
7 print "*",
8 j+=1
9 print ""
10 i+=1
输出效果如下:
*
* *
* * *
* * * *
* * * * *
#对上面的程进行深化,可以得到两个相对的三角形:
#!/usr/bin/env python
2 # coding=utf-8
3 i = 0
4 while i < 5:
5 j = 0
6 while j <= i:
7 print "*",
8 j+=1
9 print ""
10 i+=1
11 i = 5·
12 while i > 0:
13 j = 0
14 while j <= i:
15 print "*",
16 j+=1
17 print ""
18 i-=1
输出结果如下:
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
#最后上个心形:
print'\n'.join([''.join([('PYTHON!'[(x-y)%7]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(15,-15,-1)])
输出结果如下:
THON!PYTH YTHON!PYT
!PYTHON!PYTHON!PY N!PYTHON!PYTHON!P
N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTH
N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!P
!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PY
PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYT
YTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTH
THON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHO
HON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
YTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!
ON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON
YTHON!PYTHON!PYTHON!PYTHON!PYTHON
ON!PYTHON!PYTHON!PYTHON!PYTHO
PYTHON!PYTHON!PYTHON!PYTH
HON!PYTHON!PYTHON!PYT
PYTHON!PYTHON!P
ON!PYTHON
YTH
H
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341