Question

The skeleton code (starter file) for the problem is pasted below:

Some companies use letters to show their telephone numbers, in order to make the numbers easier to remember. For example, the telephone number GET-LOAN corresponds to 438-5626. Sometimes, companies might use more than 7 letters in order to make the translated number more meaningful (e.g., CALL-HOME for 225-5466, with the extra letters ignored). Complete the phoneNumber) function, which takes a single string argument that consists of at least 7 capital letters. The function returns a new string containing just the digits of the corresponding telephone number. For simplicity, we will assume that the user input consists solely of capital letters, with no digits, symbols, lowercase letters, or spaces. Use the International Standard telephone keypad (<http:lldialabc.com/motion/keypads.html>) to determine the letter-digit correspondences for your function returns a nl assume nat Uhe the Intemaionroespodencs Your function should only process the first 7 letters in a given encoded telephone number. For clarity, insert a single dash character (- after the third digit in the translated number. HINT: Start by defining a Python dictionary that maps letters to digits (use the link above to determine which letters map to which digits). HINT: use the letters as your keys, and the digits as your dictionary values. Do not simply use a series of if statements in your program! Test Input Expected Output CALLHOME GETLOAN OMNIFORALL THISISAVERYLONGNAME 225-5466 438-5626 666-4367 844-7472

def phoneNumber(letters):
result = ""
# ADD YOUR CODE HERE
return result


def loadEvents(filename):
events = {}
# ADD YOUR CODE HERE
return events

def timeline(events):
# ADD YOUR CODE HERE
return

# DO NOT modify or remove the code below! We will use it for testing.

if __name__ == "__main__":
# Problem 1: Decoding Telephone Numbers
ph = input("Enter the text to translate: ")
print("The corresponding phone number is", phoneNumber(ph))
print()

# Problem 2: Displaying a Timeline From a File
fn = input("Enter the name of the timeline data file: ")
e = loadEvents(fn)
print("Dictionary of events:", e)
print()
print("Your timeline is:")
timeline(e)
print()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PYTHON CODE FOR phoneNumber function:

# dictionary to store the letter as key, digit as value
d={'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}

# function to convert letters into digit
def phoneNumber(letters):

    # variable to store the result
    result = ""

    # looping through 0 to 6 character in the letters
    for c in letters[:7]:

        # finding the value and inserted to the result variable
        result+=str(d[c])

    # adding '-' after 3 digit
    result=result[0:3]+'-'+result[3:]

    # returning the result
    return result


def loadEvents(filename):
    events = {}
    # ADD YOUR CODE HERE
    return events

def timeline(events):
    # ADD YOUR CODE HERE
    return

# DO NOT modify or remove the code below! We will use it for testing.

if __name__ == "__main__":
    # Problem 1: Decoding Telephone Numbers
    ph = input("Enter the text to translate: ")
    print("The corresponding phone number is", phoneNumber(ph))
    print()

    # Problem 2: Displaying a Timeline From a File
    fn = input("Enter the name of the timeline data file: ")
    e = loadEvents(fn)
    print("Dictionary of events:", e)
    print()
    print("Your timeline is:")
    timeline(e)
    print()

screenshot for output:

Add a comment
Know the answer?
Add Answer to:
The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = ""...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to...

    4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME,which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters/spaces and...

  • Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone...

    Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone numbers easier to remember, some companies use letters to show their telephone number, but mapping the letters to the numbers on a standard telephone keypad: 1 2 ABC 3 DE 4G 5 11 6 MNO 7 PONS 8 Tu 9.xyz # For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone...

  • To make telephone numbers easier to remember, some companies use letters to show their telephone number....

    To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies must see more than seven letters. For example, 255-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone expressed in letters and outputs the corresponding telephone number in...

  • Letter to Number Converter: Create a program that reads a phone number as letters from a...

    Letter to Number Converter: Create a program that reads a phone number as letters from a variable and converts it to numbers e.g. GET-LOAN = 438-5626 When the company uses more than 7 letters, it should convert it to 7 digits e.g. CALL-HOME = 225-5466 The resulting converted number should include the dash to separate the three digits from the four digits Hint: Use the String object charAt method to read the variable that is storing the phone number as...

  • Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...

    Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use digits and letters (or only letters) to show their telephone number. In some cases, to make a telephone number meaningful, companies might use more than seven digits and letters. Here are some examples: Phone Number in Display Note Actual Phone Number GET LOAN - 438-5626 CALL HOME More than seven digits/letters used for ease of remembrance. 225-5466 111 GOLD - 111-4653 Glass4u - 452-7748...

  • read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment...

    read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment Topic and Requirements You are supposed to write Java program for the following questions. For every question, do provide at least THREE (3) different test cases. Question 1 Please use netbeans! joptionpane needed! Question 3 To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET...

  • I don't know how to terminate the code in the second time that whether or not...

    I don't know how to terminate the code in the second time that whether or not the users want to continue to get a new number. PLEASE HELP. To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed...

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

    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...

  • hello. i need help with number 2 ONLY 1. Use if statements to write a Java...

    hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT