Question: For this part you will write code to solve the stated problem, but not in a function. Using string functions and methods, your code must

For this part you will write code to solve the stated problem, but not in a function. Using string functions and methods, your code must take a string that represents a phone number and, using the formats listed on apache.org (reproduced below), determine which format was used and then print that format's name (see below). Once you determine which format was used, your code will then print out the prefix and line number. For example, for the phone number 1 (631) 283-2456, 631 is the area code, 283 is the prefix, and 2456 is the line number. Your code takes a string named phone and, depending on its format, first prints one of the following strings: domestic if the number starts with a ( character local if the number starts with a number other than o or 1 (Hint: use the in operator or not in syntax from the lecture notes.) international if the number starts with a + character other in all other cases Then, if the number was domestic, local or international, your code extracts the prefix and line number, printing them on separate lines. (Hint: use slicing. Remember that we can use positive or negative indices!) Do not write any input statements. To try the sample inputs given in the table below, change the value of phone in the starting code provided. Test Case # Input (phone) Output (on separate lines) 1 754-3010 local 754 3010 2 (541) 867-5309 domestic 867 5309 3 +1 (631) 632-2456 international 632 2456 4 1 (631) 632-2456 other [] phone = '754-3010' # test case #1 #phone = '(541) 867-5309 # uncomment this line to try test case #2 #phone = '+1 (631) 632-2456' # uncomment this line to try test case #3 #phone = '1 (631) 632-2456' # uncomment this line to try test case #4 # Start writing code here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
