Write a program that prompts for a phone number of 10 digits and two dashes after the area code and the next three digits of the number. (eg. 017-230-0037). Display if the phone number entered is in valid format or not and also of the phone number is valid or not.
Answer:
Code:
phone_no=input(
"Enter phone number: "
)
flag=
0
for i in range(len(phone_no)):
if i==3 or i==7:
if phone_no[i]!=
'-'
:
print(
"Invalid phone number"
)
flag=
-1
break
else:
if phone_no[i].isalpha():
print(
"Invalid phone number"
)
flag=
-1
break
if flag==
0
:
print("Valid phone number")