Using Python to read data and use it in an if statement -
i have python script writing .txt file (temperature in c). looking way read data , use in if statement.
the .txt file contains temp, ex. (20.0), , know how read data , print it, cant use data reason.
your problem expect 20.0
read file float. doesn't work way. when read file string, when say:
temp = my_data_read_from_file if temp >= 20.0: print("hot")
you're saying:
if '20.0' >= 20.0: print("hot")
strings , floats don't compare way. see mean try this:
>>> '0' > 10000 true
you need cast file input float comparison:
temp = float(my_data_read_from_file) if temp >= 20.0: print("hot")
Comments
Post a Comment