sa 11 cs chapter 9

1. 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 and not (i.e., contains just the digits and dash at specific places.

# Code p = input(‘Enter Phone Number : ‘) val = False # length must be 12 if len(p) == 12 and p[3] == ‘-‘ and p[7] == ‘-‘: if (p[:3]+p[4:7]+p[8:]).isdigit(): # all the characters except dashes should be digits val = True if val:     print(p, ‘is valid’) else:     print(p, ‘is invalid’)

1. 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 and not (i.e., contains just the digits and dash at specific places. Read More »

3. Write a program that should prompt the user to type some sentence(s) followed by “enter”. It should then print the original sentence(s) and the following statistics relating to the sentence(s) :

* Number of words * Number of characters (including white-space and punctuation) * Percentage of characters that are alpha numeric Hints * Assume any consecutive sequence of non-blank characters is a word. # Code s = input(‘Enter a sentence : ‘) number_of_words = 1 number_of_characters = len(s) al_num = 0 for i in s: if

3. Write a program that should prompt the user to type some sentence(s) followed by “enter”. It should then print the original sentence(s) and the following statistics relating to the sentence(s) : Read More »