Learn Before
Code
TypeError Example
a = input('hour') b = input('number of hours') int(a) int(b) h = a // 24 s = a % 24 print(h, s) a = a + s print( 'hour now', a)
TypeError: unsupported operand type(s) for //: 'str' and 'int' on line 5
On line 5 we are trying to use integer division on a and 24. The error message tells you that you are trying to divide a string by a number. In this case you know that 24 is a number so a must be a string. But how? You can see the function call on line 3 where you are converting a to an integer with int(a). The problem is that the expression int(a) does not assign a to the integer. The proper assignment expression here is a = int(a).
0
1
Updated 2021-06-22
Tags
Python Programming Language
Data Science