我是
Python的新手,并尝试使用一些示例脚本.我正在做一个简单的收银机类型的事情,但我想要证明或右对齐输出,使其看起来像这样:
subTotal = 24.95
tax = subTotal * 0.0725
total = subTotal + tax
paid = 30
change = paid-total
print("The subtotal was: $",subTotal)
print("The tax was: $",tax)
print("The total was: $",total)
print("The customer paid: $",paid)
print("Change due: $",change)
我知道我可以用很少的打印语句简化这个,但是我只是想让它更容易看到我正在做的事情.
我想让它输出这样的东西,注意到美元数量是一致的,而美元和美元之间没有空间.我不知道如何做这两件事情.
The subtotal was: $24.95
The tax was: $1.81
The total was: $26.76
The customer paid: $30.00
Change due: $3.24
我尝试读取格式方法的Python文档,但是我没有看到任何可以使用什么格式说明符来做某些事情的例子.提前感谢任何帮助.