Python Examples: Difference between revisions
From Lucca's Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
print(f'The monthly payment is {monthly_payment:.2f}.') | print(f'The monthly payment is {monthly_payment:.2f}.') | ||
Display a large number and add commas in-between every 3 digits. | Display a large number and add commas in-between every 3 digits. (the end result looks like this: <code>1,000,000,000</code>) | ||
large_number = 1000000000 | large_number = 1000000000 | ||
print(f'{large_number:,}') | print(f'{large_number:,}') |
Revision as of 10:39, 29 August 2025
Calculate the average of three numbers
avg = (num1+num2+num3)/3
Display a variable inside an f string and round it to only have 2 decimals, like with money
monthly_payment = 1000.0000 print(f'The monthly payment is {monthly_payment:.2f}.')
Display a large number and add commas in-between every 3 digits. (the end result looks like this: 1,000,000,000
)
large_number = 1000000000 print(f'{large_number:,}')