3
I have a question, I am a beginner and I am reading the book "Introduction to Programming with Python" 3° Edition. And I came across this code below.
Program 4.3 - Income Tax Calculation
salario = float(input('Digite o salário para cálculo do imposto.: '))
base = salario
imposto = 0
if base > 3000:
imposto = imposto + ((base - 3000) * 0.35)
base = 3000
if base > 1000:
imposto = imposto + ((base - 1000) * 0.20)
print(f'Salário: R${salario:6.2f} Imposto a pagar: R${imposto:6.2f}')
It is working but in this 'print' I did not understand "6.2f" being if I remove it will work the same way as in the example below.
Program 4.3 - Income Tax Calculation
salario = float(input('Digite o salário para cálculo do imposto.: '))
base = salario
imposto = 0
if base > 3000:
imposto = imposto + ((base - 3000) * 0.35)
base = 3000
if base > 1000:
imposto = imposto + ((base - 1000) * 0.20)
print(f'Salário: R${salario} Imposto a pagar: R${imposto}')
Have a look at "Formatted string literals" in the manual: https://docs.python.org/3/reference/lexical_analysis.html#f-strings
– anonimo