Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Coding Help. Please do 1a and 1b. Provide properly formatted code and scr

ID: 3752408 • Letter: P

Question

Python Coding Help.

Please do 1a and 1b. Provide properly formatted code and screenshot of output for each. Thanks

1a) phonenumber: This function should accept strings of the format " (xxx) Xxx-xxxx", where each X is a number 0 to 9, and return an integer. Other input values should result in None. For example, applying the function phonenumber on " (111) 555-3301"should return the integer 1115553301. Applying the function on "555-3301" should return None 1b) is leapday: This function should accept time-and-date strings formatted like"May 8, 2009 1:09:59am" and return None if the date +time is invalid (that date and time did not exist or is not written in the proper format), False-as in this example-if the time does not fall on a leap day, or True if it does fall on a leap day-as in "Feb 29, 2000 12:00:00pm". The month codes are Jan, Feb, Mar, Apr, May, Jun, Jul Auq, Sep, Oct, Nov, De

Explanation / Answer

According chegg guidelines i am answering the first question. Please ask the remaining questions separately.

Program 1a)

import re
def PhoneNumber(phone_number):
    phone_number=phone_number.replace("(", "")
    phone_number=phone_number.replace(")", "-")
    p_num_list = phone_number.split('-')
    if len(p_num_list) is not 3: # Check length of phone number
        return False
    if len(p_num_list[0]) is not 3: # Check length of each part
        return False
    if len(p_num_list[1]) is not 3:
        return False
    if len(p_num_list[2]) is not 4:
        return False
    if p_num_list[0].isdecimal() and p_num_list[1].isdecimal() and p_num_list[2].isdecimal(): # check if each part is decimal
        return p_num_list[0]+p_num_list[1]+p_num_list[2]


if __name__ == '__main__':
    p_num = input("Enter the phone number : ")
    if PhoneNumber(p_num) is False:
        print("None")
    else:
        print(PhoneNumber(p_num))

Output

Enter the phone number : (111)555-1101
1115551101

Enter the phone number : (11)55-1101
None

Enter the phone number : 111-550
None