principal = 0.05= 5= 1 while the year <= numyears := Principal * (1 + rate ) print(year, principal) + = 1
#输出:
Python express.py
(1, 1050.0)
(2, 1102.5)
(3, 1157.625)
(4, 1215.5062500000001)
(5, 1276.2815625000003)
#将 Print (year, principal) replaced with print (format (year, ' 3d '), format (Principal, ' 0.2f '))
#输出
Python express.py
(' 1 ', ' 1050.00 ')
(' 2 ', ' 1102.50 ')
(' 3 ', ' 1157.62 ')
(' 4 ', ' 1215.51 ')
(' 5 ', ' 1276.28 ')
Format (' What to Output ', ' format ')
#还可以
#将 Print (year, principal) replaced with print (' {0:3d} {1:0.2f} '. Format (Year,principal))
Python express.py
1 1050.00
2 1102.50
3 1157.62
4 1215.51
5 1276.28#print (' {0:3d} {1:0.2f} '. Format (year,principal)): 0 in front of year indicates the first position of year, the: number preceding the 1 represents the second position of the Princpal, followed by: symbol format
#字典格式输出
List = {' Name ': ' Xiaowei ', ' age ': $, ' Job ': ' Python '}
Print (' Name: {0[name]:s}; Age: {0[age]:d}; ' Job: {0[job]:s} '. Format (List)
#输出
#Name: Xiaowei; age:23; Job:python
##################################################################
#此外还可以
Print (' {year} {principal} '. Format (year=12,principal=3))
#结果
#python express.py
#12 3
#############################################################
Format of the Python output expression