+ 1
how do i get the same format in the capital culumn?
how do i get the same format in the capital culumn. it should be with , separator like this 100,000. https://code.sololearn.com/cl9cA5oDD257/?ref=app
5 Answers
+ 4
print("years{:>9}capital".format("\t"))
for years in range(1,years+1):
new_capital=capital *(interest/100+1)**years
print("{:0}{:>11}{:,.2f}".format(years,"\t",new_capital))
+ 4
Angela
d is for integers, s is for string.
or a purely f-string solution:
capital = 100_000
interest = 5
years = 10
y_zins=(interest/100)*capital
print(f"years{'capital':^15}")
for years in range(1,years+1):
new_capital=capital *(interest/100+1)**years
print(f"{years:^5}{new_capital:^15,.0f}")
print(f"\nEnd capital after {years} years is {new_capital:,.0f}")
+ 4
Detailed explanation can be found here quite far down:
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-formatted-output/
+ 3
use f.
but f is now string, so use %18s instead of %18d.
for years in range(1,years+1):
new_capital=capital *(interest/100+1)**years
f = (f"{new_capital:,.0f}")
print("%4d%18s"% \
(years, f))
+ 1
what is the meaning for s and d?