I want to put $ in front of the number in Python, how do I do it?

Asked 2 years ago, Updated 2 years ago, 11 views

Cash=6600.0

AR=6200.0

tne=25000.0

TotalAssets=Cash+AR+tne

np=5000.0

ap=25000.0

TL=np+ap

Capitalstock=7000.0

re=800.0

totalEquity=Capitalstock+re

total=TL+totalEquity

print("{0:-<42s}""{1:<2}""{2:-<42s}".format("Assets (current)","","Liabilities and Owners' Equity-",))

print("{0:21,.0f}""{2:<2}""{3:-<21s}""{4:-<21}".format("Cash",Cash,"","Liabilities",""))

print("{0:21,.0f}""{2:13,.0f}".format("Accounts Receivable",AR,"","Notes Payable",np))

print("{0:-21}""{2:14,.0f}".format("Asset(non-current)","","","Accounts Payable",ap))

print("{0:21,.0f}""{2:21,.0f}".format("Tools and equipment",tne,"","Total liabilities",TL))

print("{0:<42}""{1:<2}""{2:-<21s}""{3:-21}".format("","","Owner's equity",""))

21}".format("","","Owner's

print("{0:14,.0f}".format("","","Capitalstock",Capitalstock))

print("{0:14,.0f}".format("","","Retainede Earnings",re))

print("{0:20,.0f}".format("","","Total owner's equipity",totalEquity))

print("{0:21,.0f}""{2:21,.0f}".format("Total",total,"","Total",total))

How do I put a $ sign in front of a number when it's printed here?

python

2022-09-21 16:01

1 Answers

Python 3.6 and above

a = 100
print(f"${a}")
$100

Python 3.6 and below

a = 100
print("${0}".format(a))
$100


2022-09-21 16:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.