Just run a condition to check if temp is = 42 if it is print something. If you want to to keep looping till it hits 42 run a while true statement and if it hits 42 break it. I'm basing this off how I do it in c++ so it might be different in python
Also it its probably getting mad because it looks like your searching for 42 that would be in something like a array and since its just a plain integer it gets mad