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怎么下载easygui

分享关于Python中的题目实例

Python模块之time模块介绍

Python函数之enumerate用法介绍

盘点由Python开发的网站和应用

Python字典可变吗

继承中的mro与super详解

使用 if x is not none 还是if not x is none

Python能做什么工作

Python如何重命名文件

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




打赏

取消

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

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

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

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

评论

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