So, I am working on a small project. I am making a text-based temperature calculator but I have run into a problem with an if statement in the program, just as the title of this question suggests.
This is the code that I am having issues with.
running = True
fahr = "fahrenheit"
cel = "celsius"
kel = "kelvin"
temperatures = [fahr, cel, kel]
while running == True:
try:
temperature_type = str.lower(input("What is the current temperature unit you are using? \nFahrenheit, Celsius, or Kelvin?\n"))
except ValueError:
print("I do not understand. Please try again.")
continue
if temperature_type == any(temperatures) and not all(temperatures):
break
else:
print("Please enter a valid input.")
continue
It seems that there is something wrong with the logic that I am not seeing, and I have tried multiple combinations, even ones that are suggested from this post and none of them seem to work the way I want it to. The way I want it to work is to let the variable temperature_type be equal to only one of the temperatures such as Fahrenheit and then ask another question (which is not shown here). If the variable temperature_type does not equal any of the three, then I want to loop to repeat. The issue I am having is that no matter what I input, it always asks for the temperature. If anyone has an answer I would be thrilled to know what I am doing wrong and I would also love an explanation of the logic because I am not the best with this sort of logic yet. Thanks again for any answers and/or guidance!