1. Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers. For example, 017-555-1212 is a legal input. Display if the phone number entered is valid format or not and display if the phone number is valid or not (i.e., contains just the digits and dash at specific places).

# Code

p = input(‘Enter Phone Number : ‘)
val = False
# length must be 12
if len(p) == 12 and p[3] == ‘-‘ and p[7] == ‘-‘:
if (p[:3]+p[4:7]+p[8:]).isdigit(): # all the characters except dashes should be digits
val = True

if val:
    print(p, ‘is valid’)
else:
    print(p, ‘is invalid’)