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

Use python to do it please send me a picture or a link to download the python fi

ID: 3888360 • Letter: U

Question

Use python to do it

please send me a picture or a link to download the python file.

"""

CMPUT 175

LAB 02

You are provided with four empty functions. You should write code inside

these functions so that they perform as required. Each function also contains

instructions in the form of comments on the how to complete them. Please read

the comments carefully.

* Note that you are NOT allowed to import any other modules.

"""

LEN = 12

POS_HYPHEN_1 = 3

POS_HYPHEN_2 = 7

def check_length(phone_number):

    """

    This function should determine if the length of the phone_number is correct

    """

    return True

def check_hyphens(phone_number):

    """

    This function should determine if the hyphens are at the correct positions

    """

    return True

def check_digits(phone_number):

    """

    This function should determine if all the characters other than the

    hyphens are digits

    """

    return True

def modify(phone_number):

    """

    Given a valid phone_number, this function should replace the

    largest digits with 'X' and the second largest digits with 'Y'

    """

    modified_phone_number = ''

    return modified_phone_number

def validate(phone_number):

    """

    This function should check if phone_number input by the user is valid

    Return True if its valid otherwise return False

    """

    # Test the length of the phone number

    if check_length(phone_number) != True:

        return False

    # Test if the hyphens are placed correctly

    if check_hyphens(phone_number) != True:

        return False

    # Test if the digits are placed correctly

    if check_digits(phone_number) != True:

        return False

    return True

def main():

    while True:

        phone_number = input('Enter a phone number: ')

        # If the User enters an empty string: Exit

        if phone_number == '':

            return

        # Test if the number is valid

        if not validate(phone_number):

            print ('The phone number is not valid')

        else:

            # If the number is valid, replace the largest digit with X

            # and the second largest with Y

            print (modify(phone_number))

if __name__ == '__main__':

    main()

Explanation / Answer

def main(): phone_number= input('Please enter a phone number in the format XXX-XXX-XXXX: ') validNumber(phone_number) translateNumber(phone_number) def validNumber(phone_number): for i,c in enumerate(phone_number): if i in [3,7]: if c != '-': phone_number=input('Please enter a valid phone number: ') return phone_number elif not c.isalnum(): phone_number=input('Please enter a valid phone number: ') return phone_number return phone_number def translateNumber(phone_number): s="" for char in phone_number: if char is '1': x1='1' s= s + x1 elif char is '-': x2='-' s= s + x2 elif char in 'ABCabc': x3='2' s= s + x3 elif char in 'DEFdef': x4='3' s= s + x4 elif char in 'GHIghi': x5='4' s= s + x5 elif char in 'JKLjkl': x6='5' s= s + x6 elif char in 'MNOmno': x7='6' s= s + x7 elif char in 'PQRSpqrs': x8='7' s= s + x8 elif char in 'TUVtuv': x9='8' s= s + x9 elif char in 'WXYZwxyz': x10='9' s= s + x10 print(s)