[Type C]Q1. 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 e.g] 017-555-1212 is a legal input. Display if the phone number entered is a 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)

A nested if is an if statement that is the target of another if statement. Nested if statements mean an if statement inside another if statement.

if (condition1):
   # Executes when condition1 is true
   if (condition2): 
      # Executes when condition2 is true
   # if Block is end here
# if Block is end here

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in


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

Input a 12 digit phone number and check the 3rd and 7th index to validate presence of ‘-‘.

If the condition is satisfied, remaining places are checked to see if they are digits.

If these conditions are satisfied, phone number is valid, else it is invalid.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page