frankzhang57 发表于 2017-8-26 21:14:45

Python 技术求助

请教一下@小甲鱼:
如何利用for 关键字完成图片所示呢?

万分感谢

ba21 发表于 2017-8-26 22:47:16



length = input("Enter tringle height:")
if length.isdigit():
    length = int(length)
    space = 0
    i = length * 2 -1
    while i:
      if length < i:
            strN = '*' * (length - space // 2)
            strSpace = ' ' * space
            print(strN + strSpace + strN)
            space += 2
      elif length == i:
            strN = '*' * (length - space // 2)
            strSpace = ' ' * space
            print(strN + strSpace + strN)
      else:
            space -= 2
            strN = '*' * (length - space // 2)
            strSpace = ' ' * space
            print(strN + strSpace + strN)         
            
      i -= 1

            
      

frankzhang57 发表于 2017-8-27 07:32:59

ba21 发表于 2017-8-26 22:47


感谢!好好研究一下

ba21 发表于 2017-8-27 09:14:41

frankzhang57 发表于 2017-8-27 07:32
感谢!好好研究一下

主要是最佳
页: [1]
查看完整版本: Python 技术求助