Answered You can hire a professional tutor to get the answer.

QUESTION

PYTHON REGULAR EXPRESSIONS (2A and 2B are related to each other, please answer ALL parts) 2a) ** ONLY ONE LINE EXPRESSION NEEDED(Start with ^ and end...

PYTHON REGULAR EXPRESSIONS (2A and 2B are related to each other, please answer ALL parts)

2a) **ONLY ONE LINE EXPRESSION NEEDED(Start with ^ and end with $!! define a regular expression pattern that describes a single page specification: the integers you specify here must start with a non-0 digit. Here are examples that should match/should not match a single page specification:

Match 3 and 5-8 and 12:3 and 5-8 and 6:4 and 10-20/3 and 10:10/3

NotMatch 03 and 5-08 and 3 4 and 3 to 8 and 4/3and 4-:3 and 4-6:3

MORE INFO IF NEEDED: When we print computer documents, there is a common form used to specify the page numbers to print. Generally, commas separate page specifications, where each page specification is a single page number, or a contiguous range of pages. In a page specification, a dash or a colon can separate two numbers: for a dash, these numbers specify the first and last pages in a range to print (inclusive); for a colon, they specify the first page and how many subsequent pages to print (so 10:3 means 3 pagess starting at 10: 10, 11, and 12). Finally, if either of these forms is used, we can optionally define a slash followed by a number (call it n), which means for the page specification, print every nth page in the range (so 10-20/3 means 10 through 20 , but only every 3rd page: 10, 13, 16, and 19). define a regular expression that ensures group 1 is the first page; group 2 is a dash or colon (or None if not present); group 3 is the number after the dash or colon (or None if not present); group 4 is the number after the slash (or None if not present).

2b) PYTHON 3 LANGUAGE**** Define a function named pages that takes one str as an argument, representing a list of page specifications separated by commas, and a bool value controlling whether the pages are unique: printed only once; it returns a list, sorted in ascending order, of all the pages (ints) in the page specifications. This functionmust use the regular expression pattern you wrote for part 2a and extract (using the group function) information to create the numbers in the page specification. For example, if we called the function aspages('5-8,10:2,3,7:10/3',unique=True) it would return the list [3,5,6,7,8,10,11,13,16]; if we called pages('5-8,10:2,3,7:10/3',unique=False) it would return the list [3,5,6,7,7,8,10,10,11,13,16].

Raise an AssertionError exception (using Python's assert statement) if any page specifications fails to match the regular expression, or if any dash separator separates a higher first number from a lower second one: e.g., 10-8 raises/prints the exception AssertionError: pages: in page specification 10-8, 10 > 8.The page specification 8-8 is OK : it means only page 8.

example:

'3'

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question