官术网_书友最值得收藏!

The print_header() helper function

The print_header() helper function prints the account information to the console before transactions are printed. Specifically, the address, number of transactions, current balance, and total Bitcoins sent and received are displayed to the user. Take a look at the following code:

098 def print_header(account):
099 """
100 The print_header function prints overall header information
101 containing basic address information.
102 :param account: The JSON decoded account and transaction data
103 :return: Nothing
104 """

On lines 105 through 113, we print our values of interest using the string formatting method. During our program design, we chose to create this as a separate function in order to improve our code readability. Functionally, this code could have easily been, and originally was, in the print_transactions() function. It was separated to compartmentalize the different phases of execution. The purpose of the print statement on line 113 is to create a line of 22 left-aligned equal signs to visually separate the account information from the transactions in the console:

105     print('Address:', account['address'])
106 print('Current Balance: {:.8f} BTC'.format(
107 account['final_balance'] * 10**-8))
108 print('Total Sent: {:.8f} BTC'.format(
109 account['total_sent'] * 10**-8))
110 print('Total Received: {:.8f} BTC'.format(
111 account['total_received'] * 10**-8))
112 print('Number of Transactions:', account['n_tx'])
113 print('{:=^22}\n'.format(''))
主站蜘蛛池模板: 烟台市| 东莞市| 四平市| 卓尼县| 通河县| 葵青区| 建始县| 吴旗县| 北碚区| 普兰店市| 镇原县| 云浮市| 博白县| 辽宁省| 敦煌市| 六枝特区| 河曲县| 周宁县| 原平市| 宜州市| 古浪县| 任丘市| 阳信县| 象州县| 神农架林区| 丰顺县| 万山特区| 延长县| 乌审旗| 洪洞县| 海伦市| 应城市| 淄博市| 松溪县| 中宁县| 波密县| 梓潼县| 潢川县| 元氏县| 伊金霍洛旗| 扎鲁特旗|