Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview When applying for a bank account, accepting a job, or some other activity that is personal, it may involve the processing of someone's date

Overview

When applying for a bank account, accepting a job, or some other activity that is personal, it may involve the processing of someone's date of birth. It is critical for this type of data to be validated before being processed by a computation system. The task for this challenge is to design an algorithm and write a python script to validate a given string in various forms as the date of birth of someone and convert it into a standard format. The DOB conversion script should take a date in the following four formats: "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", and "YYYY.MM.DD" format and return the date in a standard format: 'mmm d, yyyy", where "mmm" is the three-letter abbreviated month's name, 'd' is a one or two-digit day of the month, and 'yyyy' is the four-digit year. That is, if the user enters "20201007", or "2020-10-07", or "2020/10/07", or "2020.10.07", the script will return "Oct 7, 2020". More examples to follow.

Python Coding Requirements

Required Modules and Functions:

Your python script is allowed to call all the built-in functions and the functions imported from the os, subprocess and sys modules from the standard library.

Based on the algorithm you have designed for this challenge; you should at least have the following five functions defined in your python script (see later section on the purpose of each function):

leap_year()

range_check()

sanitize()

size_check()

usage()

Input Value to be supported

Your Python script must ask the user for one value only: date in the following format with correct values in YYYY, MM, and DD should be considered as valid input data:

YYYYMMDD

YYYY/MM/DD

YYYY-MM-DD

YYYY.MM.DD

If there are no value provided, more than one value, or an invalid year, month, or day, your script should display the appropriate usage message, error code, and exit. Tests and Test results

The script should accept one value from the user, the value can be either in "YYYYMMDD", "YYYY/MM/DD", "YYYYMM-DD", or "YYYY.MM.DD" format.

If the input data does not represent a real date, your script should give an appropriate error message. Invalid months (>12) or invalid days of month (different for each month, and if the month is February, the year matter too), should be detected and give appropriate error messages. For examples:

Enter your date of birth: 2020-10-10 , and the output should be

Oct 10, 2020

Enter your date of birth: 2020-10-09 , and the output should be

Oct 9, 2020

Enter your date of birth: 2020-06-30 , and the output should be

Jun 30, 2020

Enter your date of birth: 20201010 , and the output should be

Oct 10, 2020

Enter your date of birth: 2020/10/10 , and the output should be

Oct 10, 2020

Enter your date of birth: 2020.02.29 , and the output should be

Feb 29, 2020

Enter your date of birth: 2019.02.29 , and the output should be

Error 03: wrong day entered

Enter your date of birth: 2019.13.12 , and the output should be

Error 02: wrong month entered

Enter your date of birth: 2019.06.31 , and the output should be

Error 03: wrong day entered

Enter your date of birth: 201802 , and the output should be

Error 09: wrong date entered

Enter your date of birth: 18981225 , and the output should be

Error 10: year out of range, must be 1900 or later

Enter your date of birth: 18981299 , and the output should be

Error 10: year out of range, must be 1900 or later

Enter your date of birth: 189802 , and the output should be

Error 09: wrong date entered

If something is wrong with the provided value, display the proper usage message:

Usage: YYYYMMDD|YYYY/MM/DD|YYYY-MM-DD|YYYY.MM.DD

Script structure and sample template

The following is a brief description of each function:

The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False.

The range_check() function will take an integer object and a tuple with two integer values, the first value indicates the lower bound and the second one indicates the upper bound of a integer range. If the integer object falls in between the range given in the tuple, return 'True', otherwise return 'False'.

The sanitize() function will take two string objects, the first string object is the object to be sanitized, and the 2nd string object contains letters that are allowed. This function will return the first object with letters not in the 2nd string object removed.

The size_check() function will take an collection data type object and expected number of items as an integer and will return either 'True' or 'False'. If the number of items in the data object match the integer value given, return 'True', otherwise return 'False'.

The usage() function will take no argument and return a string describing the usage of the script

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_2

Step: 3

blur-text-image_3

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

=+How does it affect the steady-state rate of growth?

Answered: 1 week ago