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?
Advertisement
Answer
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()
.