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.



Untitled 24.jpg


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



        if phone_no[i].isalpha():

            print( "Invalid phone number" )

            flag= -1


if flag== 0 :

    print("Valid phone number")

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.