Im practicing with some simple problems and using try and exceptions, I have done one below where I want to raise an exception if an int is entered instead of a str put it never seems to raise the exception. When I do it the other way round and want to raise an exception when a str is entered instead of an int it works fine though, what am I doing wrong here? Is there a different exception I should be raising in the first problem instead of ValueError?
def is_vowel():
vws = 'aeiou'
try:
x = str(raw_input("Please enter a single letter: "))
for i in vws:
if x == i:
print x +" is a vowel"
except ValueError:
print "Error message here"
is_vowel()
this one below works as Id expect
def is_int():
ints = [1,2,3,4]
try:
y = int(raw_input("Please enter a single number"))
for i in ints:
if y == i:
print str(y) + " is a number"
except ValueError:
print "Please enter a number only"
is_int()