Arduino-Python USB serial communication

Please post the whole code ................. as I cannot see the datatypes of vars and initialized value you use..... I cannot test the code here .....

OK,

What is the output of the Arduino sketch when you capture it with the serial monitor?

Does it shows the output you expect?
if so we can consider the arduino code to be correct,
if not what did you expect ?