---51---
Question:
>Write a function to compute 5/0 and use try/except to catch the exceptions.
Solution:
---52---
Question:
>Define a custom exception class which takes a string message as attribute.
Solution:
---53---
Question:
>Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the user name of a given email address. Both user names and company names are composed of letters only.
Example:
>If the following email address is given as input to the program: john@google.com
Then, the output of the program should be: john
Hints:
>Use \w to match letters.
Solution:
解法一
解法二
---54---
Question:
>Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only.
Example:
>If the following email address is given as input to the program: john@google.com
>Then, the output of the program should be: google
Solution:
---55---
Question:
>Write a program which accepts a sequence of words separated by whitespace as input to print the words composed of digits only.
Example:
>If the following words is given as input to the program: 2 cats and 3 dogs.
>Then, the output of the program should be: ['2', '3']
Hints:
>Use re.findall() to find all substring using regex.
Solution:
解法一
解法二
网友评论