I'm working on a simple program that will ask for the weather and temperature and output what clothing the user should wear. However, I've gotten to the point where I want to make sure the user can't enter "g" degrees or any other string. Is there a simple way to compare variable types? In other words, is there something along the lines of:
if (type(temp) == 'str'):
print("Invalid. Try again.")
Or something similar that isn't too complicated? Personally, I'm fine with using advanced functions and whatnot, but that would look sketchy to my CS teacher.
You pretty much have it right, just no need for the quotes.
>>> type(5) == int
True
>>> type('5') == int
False
>>> type('5') == str
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With