Q. Write a program that prompts for a phone number of 10 digit and two dashes , with dashes after the area code and the next three number .

Display if the phone number enter is valid format or not and display if the phone number is valid or not.


You can understand by Watching video :-



Answer

num = input("Enter your Phone number :- ")

if len(num)== 12 :
    if num[3]== "-" :
        if num[4:7].isdigit() :
            if num [7]== "-":
                if num[ 8 : 13 ].isdigit() :
                    if num[ : 3 ].isdigit() :
                        print("It is valid number ")
                    else :
                        print("It is not valid number ")
                else :
                        print("It is not valid number ")
            else :
                    print("It is not valid number ")
        else :
                print("It is not valid number ")
    else :
            print("It is not valid number ")
else :
        print("It is not valid number ")

Output :-

Enter your Phone number :- 017-555-1212
It is valid number

>>> 

Enter your Phone number :- 654-54633-513
It is not valid number

>>> 

Enter your Phone number :- 313-456-3113
It is valid number

>>> 

Enter your Phone number :- 56-5643-25423
It is not valid number

>>> 

Enter your Phone number :- 46-3113-55313
It is not valid number

>>>


7 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. This program is very big, can you give a shorter one? please

    ReplyDelete
    Replies
    1. Do not try to learn program.
      Try to understand only, you will find that it was very esay : )

      Delete
  2. I want dry run for this program. Please.

    ReplyDelete
    Replies
    1. You can copy the code and run it in your pc.

      Delete
  3. Can do it in much simplest way ....waste of time in writing all these

    ReplyDelete
  4. yeah too big!!!

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post