Chapter 12

Chapter 12 - String Manipulation
[Solutions for the book "Cs with Python"
by Sumita Arora for class 11]

Page 377

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

Solution : 

a=raw_input("Enter your phone no.  in format [eg - 942-559-2555] ")
if len(a)==12:
    if a[3]=='-' and a[7]=='-':
        print "Valid"
    else:
        print "Invalid"
else:
    print "You've not entered correct phone no./ proper format "

Q2) Write a program that (i) Prompt the user for a string (ii) extract all the digits from the string. (iii) If there are digits sum the collected digits else print "The string has no digits"

Solution : 

a=raw_input("Enter no.s ")

Comments

Popular posts from this blog