Question

Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whet
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1- def is_a_valid_date(a): 2 month_names = [January, February, March,April, May, June, July, Augus 3 days_in_m

1. True 2. False 3. False 4. False 5. False 6. False

def is_a_valid_date(a):
month_names = ["January","February","March","April","May","June","July","August","September","October","November","December"]
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  
a = a.split()
  
if len(a) != 2:
return False
  
if a[0] not in month_names:
return False
  
if not a[1].isdigit():
return False
  
days = days_in_month[month_names.index(a[0])]
given = int(a[1])
  
if given < 1 or given > days:
return False
  
return True
  
print("1.", is_a_valid_date("January 21"))
print("2.", is_a_valid_date("Auust 3"))
print("3.", is_a_valid_date(" June 158"))
print("4.", is_a_valid_date("February 0"))
print("5.", is_a_valid_date(" December 3k1"))
print("6.", is_a_valid_date("January 28 6"))
  

# Please up vote

Add a comment
Know the answer?
Add Answer to:
Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...

  • Define a function in pycharm (isValid) that takes a password as a parameter and returns true...

    Define a function in pycharm (isValid) that takes a password as a parameter and returns true if the password is valid or false if the password is invalid. A valid password must be at least 8 characters long and contains $, _, or @. Invoke the function and print valid or invalid according to the returned Boolean value. Sample, if (isValid(password) == True): print(“Valid”) Or, result = isValid(password) If (result): print(“invalid”)

  • Define the get_list_of_lists() function which is passed a list of strings as a parameter. An example...

    Define the get_list_of_lists() function which is passed a list of strings as a parameter. An example parameter list is: ["4 3 1 12 2 12 3 12 4 3", "4 3 1 12 2 12 3 12 4 3", "4 3 1 12 2 6"] The function returns a list of lists of tuples. For each element of the parameter list, e.g., "4 3 1 12 2 12" the function creates a list of tuples, e.g., [("4", 3), ("1", 12),...

  • Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function...

    Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function returns a string made up of the concatenation of the middle letter of each word from the parameter list. The string returned by the function should be in lowercase characters. If the parameter list is an empty list, the function should return an empty string For example Test Result print("1.", get mid_letter"Jess", "Cain", Amity", "Raeann"])) 1. siia Answer (penalty regime: 0 %) 1 -Idef...

  • Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum...

    Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum of the digits multiplied by two. A solution using a loop is expected. As an example, the following code fragment: total = double_add_digits_in_string("xx1xx2xx3xx") print (total) should produce the output: 12

  • python Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are...

    python Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person's contact information. If the person is not found, the function returns, "name not in contact". Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples: contacts =...

  • Basic Python code needed Define the get_lines_from_file) function which is passed a filename as a parameter....

    Basic Python code needed Define the get_lines_from_file) function which is passed a filename as a parameter. The function reads the information from the file (corresponding to the filename parameter) and returns a list of strings where each element of the returned list corresponds to one line of the file. The list of strings which is returned by the function should not contain any newline characters. For example, if the file contains the text: 10 440 240 4 42 4 42...

  • debug the program in java /** This program demonstrates an array of String objects. It should...

    debug the program in java /** This program demonstrates an array of String objects. It should print out the months and each day of the month. It should print out the month name and days for the month with the least days It should print out the average number of days in each month Here is what it should print when executed: January has 31 days. February has 28 days. March has 31 days. April has 30 days. May has...

  • Must be done in PHP. Details below: NOTE: in #4 part B, the split function that...

    Must be done in PHP. Details below: NOTE: in #4 part B, the split function that my teacher wants me to use in this program is: str_split() 1. Create a new document in your text editor (notepad++) 2. Type the <html element, header information, and <body element. Use String Manipulation functions as the content of the <title element 3. Add the following standard PHP script delimiters to the document body: ?php 4. In the php script section write the appropriate...

  • 7.10 Strings Implement the get_num_of_non_WS_characters() function. get_num_of_non_WS_characters() has a string parameter and returns the number of...

    7.10 Strings Implement the get_num_of_non_WS_characters() function. get_num_of_non_WS_characters() has a string parameter and returns the number of characters in the string, excluding all whitespace. Implement the get_num_of_words() function. get_num_of_words() has a string parameter and returns the number of words in the string.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT