Python program to Raise Exceptions

x = ['a','b','c','d','e']
y = input("Insert a letter: ")
if y in x:
 print(1)
else:
 raise ValueError("Letter does not exist!")

 

 

Output:

Insert a letter: a
1

 

Insert a letter: z
Traceback (most recent call last):
  File "E:\IDE\pythonProject1\programs.py", line 6, in <module>
    raise ValueError("Letter does not exist!")
ValueError: Letter does not exist!

 

Subscribe For Daily Updates

100+ Python Pattern Examplespython pattern examples - star patterns, number patterns