Knowee
Questions
Features
Study Tools

You are creating a script to validate a date. The date can be typed in either the Jan 1,2000format or the 01/01/2000format. You begin typing your code:def validateDate(date):dateValid = False months = ['', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']if date[]isdigit() is True: tempDate date.split('/') if tempDate[0] >0 dateValid = True tempDate <13:else: tempDate = date.split() if tempDate[] in months: dateValid = Trueif len(tempDate) < 3: dateValidreturn dateValidIf the user only types “3” you want the function to stop processing the date and send back a value of false.What should you type in the blank space? (Please type your answer all in lower case. Example: variable)

Question

You are creating a script to validate a date. The date can be typed in either the Jan 1,2000format or the 01/01/2000format. You begin typing your code:def validateDate(date):dateValid = False months = ['', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']if date[]isdigit() is True: tempDate date.split('/') if tempDate[0] >0 dateValid = True tempDate <13:else: tempDate = date.split() if tempDate[] in months: dateValid = Trueif len(tempDate) < 3: dateValidreturn dateValidIf the user only types “3” you want the function to stop processing the date and send back a value of false.What should you type in the blank space? (Please type your answer all in lower case. Example: variable)

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The blank space should be filled with "len(date)". This will check the length of the input date. If the length is less than 3, the function will stop processing and return false. So, the code should look like this:

def validateDate(date):
    dateValid = False
    months = ['', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
    if len(date) < 3:
        return dateValid
    if date.isdigit() is True:
        tempDate = date.split('/')
        if int(tempDate[0]) > 0 and int(tempDate[0]) < 13:
            dateValid = True
    else:
        tempDate = date.split()
        if tempDate[0].lower() in months:
            dateValid = True
    return dateValid

This code first checks if the length of the date is less than 3. If it is, it returns false. If the date is in digits, it splits the date by '/' and checks if the month (tempDate[0]) is between 1 and 12. If the date is not in digits, it splits the date by space and checks if the month (tempDate[0]) is in the list of months. If any of these conditions are met, it sets dateValid to true. Finally, it returns the value of dateValid.

This problem has been solved

Similar Questions

Design a Python function that uses regular expressions to validate dates in the format "yyyy-mm-dd." The function should return True if the date is valid and False if it's not. yyyy should be between 1000 and 2023mm should be between 01 and 12dd should be between 01 and 31Sample Input:2010-04-04Sample Output:True

Define a function named is_valid_day() which takes no parameters. The function prompts the user to enter a date and validates the day value only. The function returns True if the day value is within the specific range based on the particular month, and returns False otherwise. The months and their corresponding number of days are listed below:January, March, May, July, August, October, December: 31 days.February: 29 days (we consider a leap year for all cases).April, June, September, November: 30 days.For example:Test Input Resultprint(is_valid_day())2002-02-30Enter your birth date (yyyy-mm-dd): 2002-02-30Falseprint(is_valid_day())2003-04-31Enter your birth date (yyyy-mm-dd): 2003-04-31Falseprint(is_valid_day())2005-07-31Enter your birth date (yyyy-mm-dd): 2005-07-31True

Given a date check whether it is Valid or Invalid. If it is a valid date print "Valid" else "Invalid".INPUT:accept the date in this format - dd/mm/yyOUTPUT:Print "Valid" or "Invalid".

What will be the output of the code shown below if the system date is 18th June, 2017?tday=datetime.date.today()bday=datetime.date(2017,9,18)till_bday=bday-tdayprint(till_bday)

Question 1You are creating an application that prompts the user to enter the day of the month on which they want a transaction to occur. You are concerned that a malicious use may enter something that is not a number that is valid for the month selected. You plan to start by testing to see if the user typed in a number. Later, you will test the number to see if it’s valid for that month. What code should you add to your program?1 pointif date.isdigit() is True: code asking the user to enter a valid numberif date.isdigit is False: code asking the user to enter a valid numberif date.isdigit is True: code asking the user to enter a valid numberif date.isdigit() is False: code asking the user to enter a valid number

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.