File tree Expand file tree Collapse file tree 1 file changed +45
-4
lines changed Expand file tree Collapse file tree 1 file changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,15 @@ finally:
2828----------------
2929** My Solution: Python 3**
3030``` python
31- # to be written
31+ def divide ():
32+ return 5 / 0
33+
34+ try :
35+ divide()
36+ except ZeroDivisionError as ze:
37+ print (" Why on earth you are dividing a number by ZERO!!" )
38+ except :
39+ print (" Any other exception" )
3240
3341```
3442---------------------
@@ -64,7 +72,27 @@ error = MyError("something wrong")
6472----------------
6573** My Solution: Python 3**
6674``` python
67- # to be written
75+
76+ class CustomException (Exception ):
77+ """ Exception raised for custom purpose
78+
79+ Attributes:
80+ message -- explanation of the error
81+ """
82+
83+ def __init__ (self , message ):
84+ self .message = message
85+
86+
87+ num = int (input ())
88+
89+ try :
90+ if num < 10 :
91+ raise CustomException(" Input is less than 10" )
92+ elif num > 10 :
93+ raise CustomException(" Input is grater than 10" )
94+ except CustomException as ce:
95+ print (" The error raised: " + ce.message)
6896
6997```
7098---------------------
@@ -105,7 +133,20 @@ print r2.group(1)
105133----------------
106134** My Solution: Python 3**
107135``` python
108- # to be written
109-
136+ email = " john@google.com"
137+ email = email.split(' @' )
138+ print (email[0 ])
110139```
111140---------------------
141+ ** OR**
142+ ``` python
143+ import re
144+
145+ email = " john@google.com elise@python.com"
146+ pattern = " (\w+)@\w+.com"
147+ ans = re.findall(pattern,email)
148+ print (ans)
149+ ```
150+
151+
152+
You can’t perform that action at this time.
0 commit comments