当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | def printStar(intNum):
s = "*"
spaceLength = intNum
blockCount = int(intNum/2+1)
for i in range(spaceLength):
result = s.rjust(blockCount)
if i >= int(spaceLength/2):
print (result)
s = s[2:]
blockCount -= 1
else :
print (result)
s = s+(2* "*" )
blockCount += 1
def oddOReven(intNum):
if intNum%2 == 0:
print ( "please input a odd num data" )
else :
printStar(intNum)
if __name__ == '__main__' :
while True:
try :
intNum = eval (input( "please input a odd num data\n" ))
oddOReven(intNum)
except BaseException as e:
print ( "Please input as 1/2/3... Errorcode:%s" % e)
|
运行结果:

推荐教程:《python视频教程》
以上就是python如何输出星号组成的菱形图形?的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python怎么下载easygui
分享关于Python中的题目实例
Python模块之time模块介绍
Python函数之enumerate用法介绍
盘点由Python开发的网站和应用
Python字典可变吗
继承中的mro与super详解
使用 if x is not none 还是if not x is none
Python能做什么工作
Python如何重命名文件
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何输出星号组成的菱形图形?