Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python to do this, all the files are in this link: https://drive.google.com/drive/folders/0BzoFdHKM0HX5UmE2cUtMU1Y4WGc?usp=sharing CMPUT 175 LAB 8 Tasks: 1. Please read the comments

Please use python to do this, all the files are in this link:

https://drive.google.com/drive/folders/0BzoFdHKM0HX5UmE2cUtMU1Y4WGc?usp=sharing

""" CMPUT 175 LAB 8

Tasks: 1. Please read the comments first. 2. Construct regular expressions for the two formats (line 17-30). 3. Complete the main, extract_date and check_date functions. """

import re import sys

month_names = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]

''' Construct regular expressions for the following two date formats: 1. // where contains 4 digits; and contain 1 or 2 digits. (e.g. '11/05/2017', '06/02/2000', '6/2/1999') 2. where contains 4 digits; is a name for a month (see the variable month_names); contain 1 or 2 digits. (e.g. '18 March 2007', '1 October 1999', '2 june 2015')

You can assume that there are no digits that precede or follow the date in the string. ''' re1 = "" re2 = ""

def extract_date(string): ''' Extract the date from the string using re.match(, ). Since we initialze re1 and re2 as global variables, we can use them in this function. Then use .group() or .groups() to get the match strings. If there is a match, return [, , ] where , and are integers. If there is no match, return an invalid date (e.g, [0, 0, 0]).

Arg: string - a string

Return: [, , ] - a list of integers ''' return [0, 0, 0]

def check_date(day, month, year): ''' Check if the date is valid or not: 1. The month must be in the range [1,12]. 2. Some months have 31 days, some have 30 day, one has 28 days. If you don't know the rule, check out this link https://en.wikipedia.org/wiki/Month. You can assume that there is no leap year in the input.

Arg: day - an integer month - an integer year - an integer

Return: a Boolean value ''' return True

def main(): ''' The function reads input from stdin (line by line), extracts date in each line, checks if the date is valid and then output the message. ''' for line in sys.stdin: ''' Call extract_date() to get the date information. Remember to remove the new line char and make be lowercase. ''' # [day, month, year] = extract_date()

''' If there is a valid date, output the date in the format: "(year, month, day)". If there is no valid date, output "no date detected". ''' # if check_date(day, month, year): # do something # else: # do something

if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago