1 answer

This is Python The program should accept input from the user as either 7-digit phone number...

Question:

This is Python

The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12.

The program should not crash if the user enters invalid characters for the phone number (should be letters, digits and/or "-" (hyphen or dash) The first character cannot be a dash, and the last four characters cannot contain any dashes. The user input should not be case sensitive.

If the user enters an invalid characters on input, the program should print an appropriate error message (not just "oops!") and the user should be invited to try again, until they enter a valid phone number or type "quit".

Users should enter as many phone numbers as they want until they type "quit", at which case the program says good-bye and prints the programmer's name.

Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard

Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and 0 = 6 P, Q, R, and S = 7 T, U, and V = 8 W, X, Y, and Z = 9 Write a program that asks the user to enter a 10-character telephone number in the for- mat XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equiva- lent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663.

Answers

def convert(n):
if(n=="A" or n=="B" or n=="C"):
num=2
elif(n=="D" or n=="E" or n=="F"):
num=3
elif(n=="G" or n=="H" or n=="I"):
num=4
elif(n=="J" or n=="K" or n=="L"):
num=5
elif(n=="M" or n=="N" or n=="O"):
num=6
elif(n=="P" or n=="Q" or n=="R" or n=="S"):
num=7
elif(n=="T" or n=="U" or n=="V"):
num=8
elif(n=="W" or n=="X" or n=="Y" or n=="Z"):
num=9
else:
num=-1
return num
  
def validate(number):
if number[0]=="-":
print("The first character cannot be a dash")
return False
elif number[len(number)-1]=="-" or number[len(number)-2]=="-" or number[len(number)-3]=="-" or number[len(number)-4]=="-":
print("The last four characters cannot contain any dashes")
return False
  
number=number.replace("-","")
  
if len(number)==10 or len(number)==7:
new_number=""
if(len(number)==7):
new_number="512"
for i in range(0, len(number)):
if(number[i].isalpha()):
new_number+=str(convert(number[i]))
if(int(convert(number[i]))==-1):
print("Number contains invalid characters")
break
else:
new_number+=number[i]
n2=new_number[:3]+"-"+new_number[3:6]+"-"+new_number[6:]
print(n2)
return True
else:
print("Length is not 7 or 10")
return False
  
name=input("Enter your name: ")   
while True:
number=input("Enter 10 character telephone number: ")
if validate(number.upper()):
break
else:
stri =input("Invalid number, Want to try again?or enter quit ")
if(stri=="quit"):
break
print("Goodbye "+name+"!!")

Screenshot of code

def convert(n): if(n==A or n==B or n==C): num=2 elif(n==D or n==E or n==F): num=3 elif(n==G or n== ==H or n=

def validate(number): if number[@]==-: print(The first character cannot be a dash) return false elif number (number)-1)==

Output Screens

input Enter your name: John Enter 10 character telephone number: 555-get-Food 555-438-3663 Goodbye John!!input Enter your name: Jane Enter 10 character telephone number: 125478-PL- The last four characters cannot contain any dashe

.

Similar Solved Questions

1 answer
1 45 kg is released from rest from the top of a rough ramp, with Mass...
1 45 kg is released from rest from the top of a rough ramp, with Mass - coefficient of kinetic friction 0.25 between the block and the incline, of height 3.2 m and length d 5.5 m. At the bottom of the ramp, the mass slides on a horizontal, frictionless surface until it compresses a spring of spring ...
1 answer
Swansea Manufacturing currently produces 1,000 tires per month. The following per unit data for 1,000 tires...
Swansea Manufacturing currently produces 1,000 tires per month. The following per unit data for 1,000 tires apply for sales to regular​ customers: Direct materials $37 Direct manufacturing labor 8 Variable manufacturing overhead 13 Fixed manufacturing overhead 20 ...
1 answer
PART A A volume of 110. mL of H2O is initially at room temperature (22.00 ∘C)....
PART A A volume of 110. mL of H2O is initially at room temperature (22.00 ∘C). A chilled steel rod at 2.00 ∘C is placed in the water. If the final temperature of the system is 21.40 ∘C , what is the mass of the steel bar? Use the following values: specific heat of water = 4.18 J/(g...
1 answer
Write down the pseudocode to generate a 200μs period square wave with a 25% duty cycle....
write down the pseudocode to generate a 200μs period square wave with a 25% duty cycle. You do not need to write any Assembly, just explain the method you would use to generate this type of square wave. 3,...
1 answer
Verano Inc. has two business divisions-a software product line and a waste water clean-up product line....
Verano Inc. has two business divisions-a software product line and a waste water clean-up product line. The software business has a cost of equity capital of 10% and the waste water clean-up business has a cost o equity capital o 7%. Verano has 50% o s revenue rom software and the rest rom the waste...
1 answer
Textbook is : Analysis of algorithms Do the following exercises. 1. Draw the following digraph: G...
Textbook is : Analysis of algorithms Do the following exercises. 1. Draw the following digraph: G = ({1, 2, 3, 4, 5}, {(1,5), (3, 4), (2, 1), (4,3), (5, 1), (5, 4), (1, 4), (2, 3), (4,2), (5,2), (1, 3), (2,5)}....
1 answer
Whitman Company has just completed its first year of operations. The company's absorption costing income statement...
Whitman Company has just completed its first year of operations. The company's absorption costing income statement for the year appears below: Whitman Company Income Statement Sales (40,000 units * $4110 per unit) Cost of goods sold (40,000 units * $22 per unit) $1,644,000 880,000 Gross margin S...
1 answer
Why are London dispersion forces weak?
Why are London dispersion forces weak?...
1 answer
Couse name : physical security qes: Find an article in an IEEE or ACM journal(or any...
couse name : physical security qes: Find an article in an IEEE or ACM journal(or any other Peer Review Journal) about video technology in a security system. Read and summarize the article, and give us your reactions to the article. requirement: need reference link...
1 answer
Please write the answer the exact way they want it please Thank You!!! For the following...
Please write the answer the exact way they want it please Thank You!!! For the following reaction. 39.5 grams of sulfuric acid are allowed to react with 26.9 grams of calcium hydroxide. sulfuric acid (aq) + calcium hydroxide) calcium sulfate (s) + water (1) What is the maximum amount of calcium sulf...
1 answer
Which of the following nutrients has the most calories per gram
which of the following nutrients has the most calories per gram?a. mineralsb. carbohydratesc. fatsd. proteine. vitaminsis it C...
1 answer
In python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree...
in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper me...
1 answer
1. You are assigned to care for a 34-year-old female patient who has sustained second- and...
1. You are assigned to care for a 34-year-old female patient who has sustained second- and third-degree burns over her neck, chest, abdomen, and left arm. The burn injury occurred during a fire in her home; her spouse did not survive the fire, but, due to the patient’s critical condition, she ...
1 answer
This visualization is for questions 2a and 2b. The following dot plots display the distributions of...
This visualization is for questions 2a and 2b. The following dot plots display the distributions of daily high temperatures for the month of February 2006 in Lincoln, Nebraska; San Luis Obispo, Califormia; and Sedona Arizona. 6 70 10 20 40 10 30 40 0 60 70 0 10 2 450 7080 2a. (3 points) Which city t...
1 answer
300 lb 300 lb - 6 in.-- For the beam and loading shown, determine the range...
300 lb 300 lb - 6 in.-- For the beam and loading shown, determine the range of the distance a for which the reaction at B does not exceed 100 lb downward or 200 lb upward. D С 50 lb Sin. 12 in 4 in 300 lb 6 in. B D C 150 lb 8 in. 12 in. 4 in...
1 answer
13. Economists who work for the government are often called on to make policy recommendations. Why...
13. Economists who work for the government are often called on to make policy recommendations. Why do you think it is important for the public to be able to differentiate normative statements from positive state- ments in these recommendations?...