Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python CMPUT 175 LAB 02 You are provided with four empty functions. You should write code inside these functions so that they perform as

use python

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()

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

Step: 3

blur-text-image

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions