+ 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

27th Aug 2023, 11:08 AM
Angela
Angela - avatar
5 odpowiedzi
+ 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))
27th Aug 2023, 1:12 PM
JaScript
JaScript - avatar
+ 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}")
27th Aug 2023, 1:30 PM
Bob_Li
Bob_Li - avatar
+ 4
Detailed explanation can be found here quite far down: https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-formatted-output/
27th Aug 2023, 2:23 PM
JaScript
JaScript - avatar
+ 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))
27th Aug 2023, 1:02 PM
Bob_Li
Bob_Li - avatar
+ 1
what is the meaning for s and d?
27th Aug 2023, 1:08 PM
Angela
Angela - avatar