Python基础:画菱形,python画菱形,上次随便折腾了个画菱形,
Python基础:画菱形,python画菱形,上次随便折腾了个画菱形,
上次随便折腾了个画菱形,这次折腾一个空心的菱形以及数字的菱形空心的相对比较简单,就是在填充的时候在两头使用"*",中间仍然使用" ",用到了and or 句型数字型的很折腾,我自己都快迷糊了,有朋友有兴趣的话可以帮忙再整整
[Python]代码
#coding=utf-8while 1: n = raw_input("Please Enter the Lenth of Side:") if n == "q": break try: tmp = int(n) except: print "Wrong!" continue #实心 print "实心" for i in range(1, 2 * tmp): print abs(tmp - i) * " " + (2 * tmp - 1 - 2 * abs( i - tmp)) * "*" #空心,在实心的基础上实现。空心与实心比较,就是"*"填充的时候有区别 print "空心" for i in range(1, 2 * tmp): print abs(tmp - i) * " " + "*" + ((abs(tmp - i) == (tmp - 1)) and " " or (2 * tmp - 1 - 2 * abs( i - tmp) - 2) * " " + "*") #欢乐型一,逻辑写复杂了,自己都快晕乎了,算式几乎是凑的了,求化简 print "欢乐一" for i in range(1, 2 * tmp): t = tmp - abs(tmp - i) print abs(tmp - i) * " " + "".join([str(abs(t - a) + abs(tmp - i) + 1) for a in range(1, 2 * t)])
相关内容
- Python汉字转拼音,python汉字拼音,使用字典和转换程序
- Python打印代码执行堆栈,python打印堆栈,import trace
- 用xapian跟mmseg实现中文搜索,xapianmmseg,xapian是一个开源
- 利用 xapian 建立索引 (python 版),xapianpython,首先弄明白几
- Python去除list中的重复元素的最简单办法,python去除li
- Python中如何打印完整的执行堆栈,python打印堆栈,在py
- Erlang,Java,Groovy,javascript等语言生成随机密码,erla
- Python 模拟竖式大数乘法,python竖式大数乘法,python内置
- django接入新浪微博OAuth,djangooauth,最近将网站和新浪微
- webpy入门猜数字游戏,webpy入门猜数字,简单的猜数字游
评论关闭