嘿,伙计们,我在Python简介课上有一个作业,我的老师指出(他还没有解释),输出的某一部分必须通过format()函数正确对齐。在
到目前为止,我学到了一些关于格式的东西,比如:print(format(12345.6789,'.2f'))
print(format(12345.6789,',.2f'))
print('The number is ',format(12345.6789,'10,.3f'))
print(format(123456,'10,d'))
我很理解这些,但这是我的教授在我的课程中想要的。在
这就是需要正确的理由:
^{pr2}$
这些数字不正确,我忘记了实际值,但你明白了。在
这是我已有的密码。在#Output
print("\n\n")
print("Amount paid for the stock: $",format(stockPaid,',.2f'),sep='')
print("Commission paid on the purchase:$",format(commissionBuy,',.2f'),sep='')
print("Amount the stock sold for: $",format(stockSold,',.2f'),sep='')
print("Commission paid on the sale: $",format(commissionSell,',.2f'),sep='')
print("Profit (or loss if negative): $",format(profit,',.2f'),sep='')
那么,如何让这些值打印时右对齐,而字符串的其余部分左对齐呢?在
谢谢你们的帮助,你们一如既往的棒极了!在