format and center

'{0:-^20,.2f}'.format(a)

0 corresponds to a parameter

: Yes pilot symbols

^ Centered Less than <left justified Greater than> is right-aligned

20 is the width

Behind accuracy is two decimal places 2f is 0.2% is the percentage of reserved several decimal places, for example. '{0: .2%}' format {3.14} output of 314.00%

 

a.center (20, '*') as output: a character string centered, total width 20 * * if not filled, the space filled by default.

 

 

http://www.icourse163.org/learn/BIT-268001?tid=1206073223#/learn/forumdetail?pid=1212723173

a = input()
if eval(a)%2 == 0:
  print('请重新输入。')
else:
  for i in range(1,eval(a)+1,2):
    b = i*'*'
    print('{0:^{1}}'.format(b,a),end = '\n')

 

Guess you like

Origin www.cnblogs.com/dost4-8/p/11199873.html