159k views
3 votes
The function below takes a single string parameter: phone_number. Phone numbers will be passed in using the format '(555)867-5309'. Complete the function to return the area code (the numbers wrapped in parentheses) as a string. For example, your code should return '555' if given the phone number above. Hint: you can just use slicing for this.

User Sijo Jose
by
6.4k points

1 Answer

5 votes

Answer:

def get_area_code(phone_number):

return phone_number[1:4]

# Testing function

print(get_area_code('(555)867-5309'))

print(get_area_code('(254)867-5309'))

print(get_area_code('(181)867-5309'))

User Axnet
by
4.3k points