TypeError: unsupported operand type(s) for /: 'str' and 'str'

Deric miller picture Deric miller · Mar 5, 2013 · Viewed 133.3k times · Source
name = input('Enter name here:')
pyc = input('enter pyc :')
tpy = input('enter tpy:')
percent = (pyc / tpy) * 100;
print (percent)
input('press enter to quit')

whenever i run this program i get this

TypeError: unsupported operand type(s) for /: 'str' and 'str'

what can i do to divide pyc by tpy?

Answer

Martijn Pieters picture Martijn Pieters · Mar 5, 2013

By turning them into integers instead:

percent = (int(pyc) / int(tpy)) * 100;

In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().