python如何输出星号组成的菱形图形?


当前第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)

运行结果:

7cb5ee033f0f44f25d2a852a5a1ec2e.png

推荐教程:《python视频教程》

以上就是python如何输出星号组成的菱形图形?的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python threading模块中的join()方法

pyquery解析器无法获取标签名dom节点的解决方法

使用Python开发简单的小游戏

Python字符串截取如何操作

Python拿mac还是windows?

Python中format函数什么意思

unity3d能用Python写吗

Python中strip()函数有什么用法

安装Python后怎么用

Python入门看什么

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...