1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
guajiro [1.7K]
3 years ago
4

Write a program that asks the user to enter a 10 character telephone number in the format XXX-XXX-XXXX. The application should d

isplay the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD the application should display 555-438-3663.
def main():
#character string
numeric_phone=" "

#user inputs phone number
alpha_phone = input('Enter 10-Digit phone number: ')

digit_list = ["2", "3","4", "5", "6", "7", "8", "9", "0"]



for ch in alpha_phone:
if ch.isalpha():
ch = ch is upper()
Computers and Technology
1 answer:
Umnica [9.8K]3 years ago
8 0

Answer:

import re  

dict = {

   "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",

 }  

def phoneAlphaConverter(dict, text):

 # Create a regular expression  from the dictionary keys

 regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys())))

 

 # For each match, look-up corresponding value in dictionary

 return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text)  

alpha_phone = input('Enter 10-Digit phone number: ').upper()

print(phoneAlphaConverter(dict, alpha_phone))

Explanation:

The programming language used is python 3.

The numeric equivalent of alphabets are as follows:

  • 2 ABC
  • 3 DEF
  • 4 GHI
  • 5 JKL
  • 6 MNO
  • 7 PQRS  
  • 8 TUV
  • 9 WXYZ

In the code, It begins by importing the regular expression module which will allow us carry out special string operations on text.

Next, a dictionary is defined to hold all the alphabets and their number equivalent.

A function that would carry out the replacement of alphabets with their numbers is created; In the function, a regular expression is created with the dictionary keys (Alphabet), and for each dictionary key, the function will substitute it with its value (Number) and return it.

Finally, the code prompts the user to enter a 10-digit number, converts all the alphabets in the input to upper case using the .upper() method, The code calls the function and prints the result.

check attachment to see code in action.

You might be interested in
PLEASSEE HELP ILL GIVE U A BRAINLIEST IF UR RIGHT!!
Nana76 [90]
It is digital signal 
5 0
3 years ago
Read 2 more answers
Which is a correct explanation of first lines?
tatyana61 [14]

The correct explanation of the first line in poems is; Choice B; The first lines determine all of the poet's subsequent choices.

<h3>Meaning of poem</h3>

By literature definition, a poem is a piece of writing in which the words are chosen for their beauty and sound and are carefully arranged, often in short lines which rhyme.

To ensure that these short lines in poems rhyme, the first line serves as a template and consequently, determines all of the poet's subsequent choices.

Read more on poems and first line;

brainly.com/question/4343450

8 0
3 years ago
What is the difference, if any, between a Portable Media Player (PMP) and a Digital Media Device (DMD)? PMPs can be analog or di
lara [203]

Answer:

PMPs are typically referred to interchangeably.

Explanation:

3 0
3 years ago
write an expression taht evaluated to true if and only if the variable s does not contain the string 'end'
natima [27]

Answer:

//check which string is greater

if(strcmp(name1,name2)>0)

//assign name1 to first, if the

    //name1 is greater than name2

    first=name1;

else

    //assign name2 to first, if the

    //name2 is greater than name1

    first=name2;

5)

//compare name1 and name2

    if(strcmp(name1,name2)>0)

   

         //compare name1 and name3

         if(strcmp(name1,name3)>0)

       

             //assign name1 to max, becuase

             //name1 is greater than name2 and name3

             max=name1;

       

Explanation:

7 0
3 years ago
To create an instance of Big Decimal for 454.45, use ________.
agasfer [191]

Answer:

C.

Explanation:

Based on the Java documentation; when creating an instance of BigDecimal, we can pass a string as a constructor.

System.out.println(new BigDecimal("454.45"));

8 0
4 years ago
Other questions:
  • 10 facts about turbines
    11·2 answers
  • Plese give three examples of specilized servers.
    13·2 answers
  • Which of the following is a proper use of the application NetStumbler?Which of the following is a proper use of the application
    10·2 answers
  • You realize your computer has been infected with malware. The program has been copying itself repeatedly, using up resources. Wh
    10·1 answer
  • Your customer asks you if it would be worth the investment for him to have Ethernet cabling installed to reach each of his works
    6·1 answer
  • How does a Graphical User Interface (GUI) interact with a desktop or laptop computer?
    11·1 answer
  • Anybody know this? Read the following scenario. Using complete sentences, explain which part of the CIA triad has been broken. M
    11·1 answer
  • How do I log into PGCPS?
    14·1 answer
  • What is a Web server application?
    7·1 answer
  • What is a shortcut for adding a timeline marker
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!