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
>>>
This program is very big, can you give a shorter one? please
ReplyDeleteDo not try to learn program.
DeleteTry to understand only, you will find that it was very esay : )
I want dry run for this program. Please.
ReplyDeleteYou can copy the code and run it in your pc.
DeleteCan do it in much simplest way ....waste of time in writing all these
ReplyDeleteyeah too big!!!
ReplyDeletecomment....
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )