鱼C论坛

 找回密码
 立即注册
查看: 5971|回复: 3

[已解决]Python 技术求助

[复制链接]
发表于 2017-8-26 21:14:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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

万分感谢
最佳答案
2017-8-26 22:47:16


  1. length = input("Enter tringle height:")
  2. if length.isdigit():
  3.     length = int(length)
  4.     space = 0
  5.     i = length * 2 -1
  6.     while i:
  7.         if length < i:
  8.             strN = '*' * (length - space // 2)
  9.             strSpace = ' ' * space
  10.             print(strN + strSpace + strN)
  11.             space += 2
  12.         elif length == i:
  13.             strN = '*' * (length - space // 2)
  14.             strSpace = ' ' * space
  15.             print(strN + strSpace + strN)
  16.         else:
  17.             space -= 2
  18.             strN = '*' * (length - space // 2)
  19.             strSpace = ' ' * space
  20.             print(strN + strSpace + strN)         
  21.             
  22.         i -= 1

  23.             
  24.         
复制代码
捕获.JPG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-8-26 22:47:16 | 显示全部楼层    本楼为最佳答案   


  1. length = input("Enter tringle height:")
  2. if length.isdigit():
  3.     length = int(length)
  4.     space = 0
  5.     i = length * 2 -1
  6.     while i:
  7.         if length < i:
  8.             strN = '*' * (length - space // 2)
  9.             strSpace = ' ' * space
  10.             print(strN + strSpace + strN)
  11.             space += 2
  12.         elif length == i:
  13.             strN = '*' * (length - space // 2)
  14.             strSpace = ' ' * space
  15.             print(strN + strSpace + strN)
  16.         else:
  17.             space -= 2
  18.             strN = '*' * (length - space // 2)
  19.             strSpace = ' ' * space
  20.             print(strN + strSpace + strN)         
  21.             
  22.         i -= 1

  23.             
  24.         
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-27 07:32:59 | 显示全部楼层

感谢!好好研究一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-27 09:14:41 | 显示全部楼层
frankzhang57 发表于 2017-8-27 07:32
感谢!好好研究一下

主要是最佳
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 17:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表