首页 > 其他 > 详细

从控制台输入n,利用format方法生成一个星号三角形

时间:2019-12-28 17:23:01      阅读:130      评论:0      收藏:0      [点我收藏+]
floorStr = input(请输入一个层数:)
floor = int(floorStr)
num = floor * 2 -3   # 17
while floor > 0:
    print("{:<{a}}{:*<{b}}".format(" ","",a =floor,b=(num - (floor - 2)*2)))
    floor -= 1
‘‘‘
print("{:<10}{:*<1}".format(" ",""))
print("{:<9}{:*<3}".format(" ",""))
print("{:<8}{:*<5}".format(" ",""))
print("{:<7}{:*<7}".format(" ",""))
print("{:<6}{:*<9}".format(" ",""))
print("{:<5}{:*<11}".format(" ",""))
print("{:<4}{:*<13}".format(" ",""))
print("{:<3}{:*<15}".format(" ",""))
print("{:<2}{:*<17}".format(" ",""))
print("{:<1}{:*<19}".format(" ",""))
‘‘‘

从控制台输入n,利用format方法生成一个星号三角形

原文:https://www.cnblogs.com/ppystudy/p/12112254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!