. Advertisement .
..3..
. Advertisement .
..4..
I am new to python and searching the “typeerror: unsupported operand type(s) for /: ‘str’ and ‘str’” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:
name = input('Enter name here:')
pyc = input('enter pyc :')
tpy = input('enter tpy:')
percent = (pyc / tpy) * 100;
print (percent)
input('press enter to quit')
The error I’m getting is below:
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Please give me the solution to this issue.
The cause: The typeerror: unsupported operand type(s) for /: ‘str’ and ‘str’ happens because the division operator cannot be used with two strings. They’re strings since all of your code’s input is run through strings.
Solution:
You should convert to make them not-strings.
The
int
function is one technique to convert a string to an integer. Consider the following one:Learn to read error messages. It tells you that you cannot use two strings with divide operator.
Ask yourself why they are strings, and what you can do to make them not-strings. Because all input is via strings, they are strings. Converting them will make them not-strings.
The int function is one way to convert strings to integers. Take this example: