anonymous
  • anonymous
Medal + fan if you solve the problem: Many companies use telephone numbers such as 800-GET-REAL to make it easier for customers to remember phone numbers. On a standard telephone keypad, the letters of the alphabet are typically mapped to numbers as follows: Write a program that asks the user to enter a telephone number in the format XXX-XXX-XXXX (dashes included). Your program must eventually display the telephone number with all alphabetic characters translated into their numeric equivalents. First check to make sure the length of the input is 12 characters; if not, display an error m
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
First check to make sure the length of the input is 12 characters; if not, display an error message and exit the program. If the length is correct, you can assume that the characters entered are in the proper format. As an example, if the user enters 800-GET-REAL, your program must then display 800-438-7325. As another example, if the user enters THE-123-4YOU, your program must then display 843-123-4968. As another example, if the user enters OMG-LOL-ROFL, your program must then display 664-565-7635.
anonymous
  • anonymous
have done anything?
anonymous
  • anonymous
No

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

Telemain
  • Telemain
This program will work as long as you pass the function a string with 12 characters. I didn't add any assertions for length, type, or structure, but there's a brief test brace to check that it's working for the correct type of inputs: def telephoneTranslator(number): """Translates telephone numbers that contain numbers and letters into only numbers. Must be 12 characters long, including dashes. Takes a string input of 12 digits, containing numbers, letters, and dashes only. Returns a string of 12 digits containing numbers and dashes only. """ translatorDict = {"A":2, "B":2, "C":2, "D":3, "E":3, "F":3, "G":4, "H":4, "I":4, "J":5, "K":5, "L":5, "M":6, "N":6, "O":6, "P":7, "Q":7, "R":7, "S":7, "T":8, "U":8, "V":8, "W":9, "X":9, "Y":9, "Z":9} translatedNumber = '' for digit in number: if str.isdigit(digit) or digit == '-': translatedNumber += digit else: translatedNumber += str(translatorDict[str.capitalize(digit)]) return translatedNumber def testbrace(): testsuccess = True if telephoneTranslator("800-GET-REAL") != "800-438-7325":testsuccess = False if telephoneTranslator("THE-123-4YOU") != "843-123-4968":testsuccess = False if telephoneTranslator("OMG-LOL-ROFL") != "664-565-7635":testsuccess = False if telephoneTranslator("omg-LOL-ROFL") != "664-565-7635":testsuccess = False if testsuccess == True: print "Test brace passed." else: print "Test brace failed."
Telemain
  • Telemain
By the way, here's some example assertions you could use to ensure length, structure, and content of the phone number passed to the function: assert len(number) == 12, "Wrong length" assert number[3] == '-', "Missing hyphen" assert number[7] == '-', "Missing hyphen" for digit in number: assert str.isdigit(digit) or str.isalpha(digit) or digit == '-', "Wrong format; only characters, numbers and hyphens"

Looking for something else?

Not the answer you are looking for? Search for more explanations.