(Solved) : Provided File A8q2functionspy Ll Find Two Functions Isvalidphonenumber Returns True Provid Q42452972 . . .

In the provided file a8q2_functions.py youll find two functions: isValidPhoneNumber (): Returns True if the provided phone na8q2_functions.py Jdef isValid PhoneNumber (number) : 1 2 Verifies whether the provi ded phone number is correctly formatted23 def validatePhone Book (phone book 24 25 Verifies whether every phone book record (dictionary) in a phone book (List) has41 # a sample phone book BEFORE validate PhoneBook ( ) is called on it: 42 #[ { name: Department of Computer Science, 43Evaluation 3 marks: Your test driver for isValidPhone Number () contains at least 6 appropriate test cases. 3 marks: Your tes

Your help is appreciated and I will give 5 stars!!

In the provided file a8q2_functions.py you’ll find two functions: isValidPhoneNumber (): Returns True if the provided phone number (represented as a string) is cor- rectly formatted. otherwise False. To be considered correctly formatted. phone numbers must be written as ###- ###-#***, where # is a digit between O and 9. validatePhoneBook (): A phone book is a list where each entry is a phone book record (represented as a dictionary: see below for more details). This function checks each phone book record in the phone book for correctly formatted phone numbers. A phone book record is a dictionary which initially has two keys: the key “name” mapped to the contact’s name (string) and the key “phone number” mapped to that contact’s phone number (also a string). validatePhone Book () adds a new key “valid” to the record with the value True if the phone number is formatted correctly, otherwise False. Here is how a sample phone book might look before and after validatePhoneBook (): # before : “Department of Computer Science ” , [“name” “phone number ” : “306-966 -4886” }, : “Department of History”, “phone number” ” 306.966.8712″ ] “name” # after “name”: “Department of Computer Science” , “phone number” : “306-966-4886”, “valid ” : True }, “name” “Department of History”, “phone number” : “306.966.8712”, “valid False } ] The provided functions contain errors. Your task will be to find the errors by systematically testing. You’ll hand in an explanation of what the errors are, and how you fixed them, but you will not hand in the corrected code. Part of the exercise is figuring out what the code is supposed to do based on the documentation! 1 Write white-box and black-box tests for the function isValidPhoneNumber (). You should do this with- out Python, either on paper, or in a simple document. Don’t worry about running your tests until you have thought about which test cases you want. Make sure you have at least 3 black-box tests and 3 white-box tests. More tests may be useful. 2. Implement a test driver using your test cases in a document named a8q2_testing.py. This should be done using the techniques seen in the textbook (Chapter 15) and as demonstrated in class (Chapter 15 Exercise 3) 3. Run your tests and copy/paste the console output to a document named a8q2_output.txt. The console output you hand in should come from the program before you try to fix it! 4. Try to deduce the problems with the isValidPhoneNumber () function from the output of your testing Then fix the error(s) in the function! 5. In the document a8q2_output.txt, describe the errorts) you found and how you fixed it (them). You do not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the functions. 6. Repeat the above steps for the second function validatePhoneBook () . a8q2_functions.py Jdef isValid PhoneNumber (number) : 1 2 Verifies whether the provi ded phone number is correctly formatted should be formatted as #-###-##*# where # can be any digit from 0-9. 4 5 Eparam number: phone number (stored as a string) 6 return: True if the phone number string is correctly formatted, otherwise False 7 # Check thelength requirement 10 if len(number) – 1 != 12: 11 return False 12 13 # Check if the dashes are in the right spot 14 if number[3] != ‘-‘ and number [7] != ‘-‘: 15 return False 16 17 #Check if non – dash characters are digits in the set “0” – “9” 18 for i in [1,2,4,5,6,7,8,9,10]: 19 if number[i] not in [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]: 20 return False 21 TA return True 22 23 23 def validatePhone Book (phone book 24 25 Verifies whether every phone book record (dictionary) in a phone book (List) has a correct ly 26 formatted phone number 27 28 Adds a new key “valid” to each phone book record with the value True if that record’s phone 29 number is correctly formatted, otherwise False 30 31 Eparam phone_book: A list of phone book dictionary records, where each record has the key “name” 32 mapped to a string and “phone number” mapped to a string 33 34 for record in phone_book: 35 number = record [ ” phone number” ] if not isValidPhoneNumbe r (number) : 36 37 record[“valid”] = True 38 else: 39 record[“valid “] = False 40 41 41 # a sample phone book BEFORE validate PhoneBook ( ) is called on it: 42 #[ { “name”: “Department of Computer Science”, 43 “phone number” : “306-966-4886 ” }, 44 { “name” : “Department of History”, 45 “phone number” : “306.966 .8712” }, 46 “name”: “Department of Psychology” , “phone number” : “(306) 966 -6657” } #t 47 48 # 1 49 50 # the same sample phone book AFTER validate PhoneBook() is called on it, assuming all errors have been corrected: 51 # [ { “name” : “Department of Computer Science”, 52 “306-966 – 4886 ” , “phone number” 53 : “valid” : True }, #t 54 “name”: “Department of History”, 55 “phone number” : “306.966.8712”, 56 “valid” : False }, 57 “name” : “Department of Psychology”, 58 “phone number” : “(306) 966-6657” , “valid” False } 59 60 61 Evaluation 3 marks: Your test driver for isValidPhone Number () contains at least 6 appropriate test cases. 3 marks: Your test driver for validatePhone Book () contains at least 6 appropriate test cases 2 marks: The output of your test drivers reveal faults in the starter code. 3 marks: You correctly identified 3 errors in isValidPhoneNumber () and explained briefly how you fixed them. 1 mark: You correctly identified 1 error in validatePhoneBook () and explained briefly how you fixed it Show transcribed image text In the provided file a8q2_functions.py you’ll find two functions: isValidPhoneNumber (): Returns True if the provided phone number (represented as a string) is cor- rectly formatted. otherwise False. To be considered correctly formatted. phone numbers must be written as ###- ###-#***, where # is a digit between O and 9. validatePhoneBook (): A phone book is a list where each entry is a phone book record (represented as a dictionary: see below for more details). This function checks each phone book record in the phone book for correctly formatted phone numbers. A phone book record is a dictionary which initially has two keys: the key “name” mapped to the contact’s name (string) and the key “phone number” mapped to that contact’s phone number (also a string). validatePhone Book () adds a new key “valid” to the record with the value True if the phone number is formatted correctly, otherwise False. Here is how a sample phone book might look before and after validatePhoneBook (): # before : “Department of Computer Science ” , [“name” “phone number ” : “306-966 -4886” }, : “Department of History”, “phone number” ” 306.966.8712″ ] “name” # after “name”: “Department of Computer Science” , “phone number” : “306-966-4886”, “valid ” : True }, “name” “Department of History”, “phone number” : “306.966.8712”, “valid False } ] The provided functions contain errors. Your task will be to find the errors by systematically testing. You’ll hand in an explanation of what the errors are, and how you fixed them, but you will not hand in the corrected code. Part of the exercise is figuring out what the code is supposed to do based on the documentation! 1 Write white-box and black-box tests for the function isValidPhoneNumber (). You should do this with- out Python, either on paper, or in a simple document. Don’t worry about running your tests until you have thought about which test cases you want. Make sure you have at least 3 black-box tests and 3 white-box tests. More tests may be useful. 2. Implement a test driver using your test cases in a document named a8q2_testing.py. This should be done using the techniques seen in the textbook (Chapter 15) and as demonstrated in class (Chapter 15 Exercise 3) 3. Run your tests and copy/paste the console output to a document named a8q2_output.txt. The console output you hand in should come from the program before you try to fix it! 4. Try to deduce the problems with the isValidPhoneNumber () function from the output of your testing Then fix the error(s) in the function! 5. In the document a8q2_output.txt, describe the errorts) you found and how you fixed it (them). You do not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the functions. 6. Repeat the above steps for the second function validatePhoneBook () .
a8q2_functions.py Jdef isValid PhoneNumber (number) : 1 2 Verifies whether the provi ded phone number is correctly formatted should be formatted as #-###-##*# where # can be any digit from 0-9. 4 5 Eparam number: phone number (stored as a string) 6 return: True if the phone number string is correctly formatted, otherwise False 7 # Check thelength requirement 10 if len(number) – 1 != 12: 11 return False 12 13 # Check if the dashes are in the right spot 14 if number[3] != ‘-‘ and number [7] != ‘-‘: 15 return False 16 17 #Check if non – dash characters are digits in the set “0” – “9” 18 for i in [1,2,4,5,6,7,8,9,10]: 19 if number[i] not in [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]: 20 return False 21 TA return True 22 23
23 def validatePhone Book (phone book 24 25 Verifies whether every phone book record (dictionary) in a phone book (List) has a correct ly 26 formatted phone number 27 28 Adds a new key “valid” to each phone book record with the value True if that record’s phone 29 number is correctly formatted, otherwise False 30 31 Eparam phone_book: A list of phone book dictionary records, where each record has the key “name” 32 mapped to a string and “phone number” mapped to a string 33 34 for record in phone_book: 35 number = record [ ” phone number” ] if not isValidPhoneNumbe r (number) : 36 37 record[“valid”] = True 38 else: 39 record[“valid “] = False 40 41
41 # a sample phone book BEFORE validate PhoneBook ( ) is called on it: 42 #[ { “name”: “Department of Computer Science”, 43 “phone number” : “306-966-4886 ” }, 44 { “name” : “Department of History”, 45 “phone number” : “306.966 .8712” }, 46 “name”: “Department of Psychology” , “phone number” : “(306) 966 -6657” } #t 47 48 # 1 49 50 # the same sample phone book AFTER validate PhoneBook() is called on it, assuming all errors have been corrected: 51 # [ { “name” : “Department of Computer Science”, 52 “306-966 – 4886 ” , “phone number” 53 : “valid” : True }, #t 54 “name”: “Department of History”, 55 “phone number” : “306.966.8712”, 56 “valid” : False }, 57 “name” : “Department of Psychology”, 58 “phone number” : “(306) 966-6657” , “valid” False } 59 60 61
Evaluation 3 marks: Your test driver for isValidPhone Number () contains at least 6 appropriate test cases. 3 marks: Your test driver for validatePhone Book () contains at least 6 appropriate test cases 2 marks: The output of your test drivers reveal faults in the starter code. 3 marks: You correctly identified 3 errors in isValidPhoneNumber () and explained briefly how you fixed them. 1 mark: You correctly identified 1 error in validatePhoneBook () and explained briefly how you fixed it

Expert Answer


Answer to In the provided file a8q2_functions.py you’ll find two functions: isValidPhoneNumber (): Returns True if the provided ph…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?