Mar-22-2019, 05:39 AM
I am very new to python but do have some coding experience but for the life of me cannot get my head around this issue I am having.
When I hard code a number into my IF statement the code runs fine without any issues as shown below.
When I hard code a number into my IF statement the code runs fine without any issues as shown below.
average = totaltime / count if average > 5: # print with a red background print ("\033[1;37;41m\r") print round(average,2), "Average load rate" print ("\033[1;37;40m\r") else: # print with a green background print ("\033[1;37;42m\r") print round(average,2), "Average load rate" print ("\033[1;37;40m\r") print ("\033[1;37;44m WAITING FOR TAG \n") print ("\033[1;37;40m\r")However if I replace the 5 in the if statement with a variable which was set by an input statement the code always runs through the else statement regardless of the value entered.
target = raw_input('Target time in seconds: ') print round(timeC,2), "Seconds", (target),"Target" if average > target: # print with a red background print ("\033[1;37;41m\r") print round(average,2), "Average load rate" print ("\033[1;37;40m\r") else: # print with a green background print ("\033[1;37;42m\r") print round(average,2), "Average load rate" print ("\033[1;37;40m\r") print ("\033[1;37;44m WAITING FOR TAG \n") print ("\033[1;37;40m\r")I have tried print out the values before the IF statement to check the values and ensure another part of the code is having an effect. I have also found an online debugger and ran through the code and no matter what I did the code ran fine. However when I run the code on my RaspPi it always defaults to the ELSE when I change the code to a variable. I have tried to INT the variables, ive put the statement in brackets. I am now pulling my hair out.