Sale!

Regular Expression Assignment solution

$30.00

Regular Expression Assignment
Python Features Required: Regular Expressions
File(s) to Submit: regex.py
Specification Download the file regex.py, which contains two custom exceptions
(BadPasswordCharacter and InvalidFractionExpression); and incomplete
definitions for the three functions below. You are to fill in the code for these functions.
1. strong_pwd(pwd_string)
Uses regular expressions to make sure a password string is strong. The password may
only contain uppercase and lowercase characters and digits. It should raise a
BadPasswordCharacter exception is this is not true.

Category:

Description

5/5 - (3 votes)

Regular Expression Assignment
Python Features Required: Regular Expressions
File(s) to Submit: regex.py
Specification Download the file regex.py, which contains two custom exceptions
(BadPasswordCharacter and InvalidFractionExpression); and incomplete
definitions for the three functions below. You are to fill in the code for these functions.
1. strong_pwd(pwd_string)
Uses regular expressions to make sure a password string is strong. The password may
only contain uppercase and lowercase characters and digits. It should raise a
BadPasswordCharacter exception is this is not true.
A strong password is defined as one that is at least eight characters long, contains both
uppercase and lowercase characters, and has at least one digit. You may need to test
the string against multiple regex patterns to validate its strength.
2. clear_whitespace(s) Returns the string s with all whitespace characters
removed. Use the re.sub method.
3. extract_from_equation(s)
The string s is supposed to represent a sum, difference, product or quotient of two
fractions. While the string represents an expression connecting two fractions by an
operator symbol (+,-,*,/), the string may have whitespace anywhere in the string (except
within the strings representing integers). Use the previous function to clear out all
whitespace. Then try to use a regular expression to extract and return five substrings
representing: the first fraction’s numerator, the first fraction’s denominator, the operator,
the second fraction’s numerator, and the second fraction’s denominator.
You should raise a InvalidFractionExpression if the string does not represent an
expression as described above.