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.
Answers
Answered by
18
Explanation:
The Code for the program stated in question statement is as follows;
CODE
num = input(‘Input your Phone Number : ‘)
value = False ## length must be 12
if len(num) == 12 and num[3] == ‘-‘ and num[7] == ‘-‘:
if (num[:3]+num[4:7]+num[8:]).isdigit(): ## checking that all the characters are digits excluding the dashes
value = True
if value = True:
print(num, ‘is valid’)
else:
print(num, ‘is invalid’)
Answered by
4
Answer:
this is the best answer , pls mark me as brainliest
Attachments:
Similar questions