JavaScript
x
7
1
name = input('Enter name here:')
2
pyc = input('enter pyc :')
3
tpy = input('enter tpy:')
4
percent = (pyc / tpy) * 100;
5
print (percent)
6
input('press enter to quit')
7
whenever i run this program i get this
JavaScript
1
2
1
TypeError: unsupported operand type(s) for /: 'str' and 'str'
2
what can i do to divide pyc by tpy?
Advertisement
Answer
By turning them into integers instead:
JavaScript
1
2
1
percent = (int(pyc) / int(tpy)) * 100;
2
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()
.