Typeerror: not all Arguments converted During string formatting (what should I do?)

Asked

Viewed 22 times

-5

I’m solving a simple question of calculating tax on a salary:

sal=float(input('digite o valor:'))
if   sal>3000:
    percent=0.25
elif sal>2000:
    percent=0.20
elif sal>1000:
    percent=0.10
else         :
    percent=0.5
imposto=sal*percent
salliquido=sal-imposto
print('salário: R$%6.2f'%sal)
print('imposto: R$%6.2f'%imposto)
print('salário liquido: R$6.2f'%salliquido)

But when I run the python returns the following error:

digite o valor:1500
salário: R$1500.00
imposto: R$150.00
Traceback (most recent call last):
TypeError: not all arguments converted during string formatting

Where am I going wrong?

  • 3

    At last print lacked the % before the 6.2. While you’re at it, take a look at f-string, that can help you

1 answer

-1


you forgot to put a % in the last print after the dollar ( R$ ) your code is so: print('salário liquido: R$6.2f'%salliquido)

and the right thing would be: print('salário liquido: R$%6.2f'%salliquido)

is just a real lack of attention!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.