-2

I tried this code to output 5% as a tax.

income = input('How much is your income?')

tax =  income / 20



print('The tax would be  ' + tax )

Why does it not work this way?

It gave me an error.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
  • 2
    As for why it does not work that way, a string is not a number. What is the answer to `"Hello" / 20`? – G. Anderson Mar 26 '20 at 22:11
  • 1
    Never say "it gave me an error" without adding that specific error. Python gives an extensive traceback; including it in your post helps us help you. – Jongware Mar 26 '20 at 22:28

1 Answers1

0

input returns a string by default. You need to manually cast it to an int or float like so:

income = float(input('How much is your income?'))
Bob Smith
  • 220
  • 4
  • 21