So I am trying to write a small script in python that will differentiate inputs, and when the appropriate input is given, an int
, it will give the correlating answer. I know there are a number of posts on this topic that are similar but I was having trouble finding my answer. Here is what I have.
oktas = input("Oktas: ")
def sky_condition(oktas):
if isinstance(oktas, int) == True:
if oktas == 0:
print ("CLR")
elif oktas == 1 or oktas == 2:
print ("FEW")
elif oktas == 3 or oktas == 4:
print ("SCT")
elif oktas >= 5 and oktas <= 7:
print ("BKN")
elif oktas == 8:
print ("OVC")
elif oktas < 0 or oktas > 8:
raise ValueError("Oktas provided are above or below the allowed limits.")
elif isinstance(oktas, int) == False:
raise NameError("You suck at following instructions.")
skycondition(oktas)
When you put in an int
or a str
(as in something in "quotation marks") then it processes everything as it should. However if I just put a letter or word without quotation marks, for example h, it raises the error
NameError: name 'h' is not defined
It produces the error I want but not how I wanted it. How can I code it so it will raise the error how I want it?