background:
Bmpixel
194***4370@qq.com
List reversal function:
#!/user/bin/python
#-*-coding:utf-8-*-
def reverse (LI):
for I in range (0, Len (LI)/2):
temp = Li[i]
li[i] = li[-i-1]
li[-i-1] = temp
L = [1, 2, 3, 4, 5]
reverse (L)
print (L)
Error message in Python3: ' Float ' object cannot be interpreted as an integer, and in Python2 normal operation;
Problem Solving
Why is the data in the range float?
There is a difference between py2 and py3, and there is a difference in the search. Please see the following usage:
Pyhon2
C:\users\chenjun>python
Python 2.7.12 (v2.7.12:d33e0cf91556, June 2016, 15:24:40) [MSC v.1500-bit (
AMD64)] on Win32
Type ' help ', ' copyright ', ' credits ' or ' license ' for the more information.
>>> 0/200 + 1
1
>>> 1/200 + 1
1
Python3
C:\users\chenjun>python3
Python 3.6.1 (V3.6.1:69C0DB5, Mar 2017, 17:54:52) [MSC v.1900 bit (Intel)]
On Win32
Type ' help ', ' copyright ', ' credits ' or ' license ' for the more information.
>>> 0/200 + 1
1.0
>>> 1/200 + 1
1.005
In the python2,/only left the integer part, minus the decimal, is int type. In Python3, the result is division in real sense, and the result is float type. So there is the error message: ' Float ' object cannot is interpreted as an integer.
Workaround: Convert a float type to an int type