Question: *Python Program- 2 PARTS- Required test program posted in the end* 1. Decoding Telephone Numbers Some companies use letters to show their telephone numbers, in

*Python Program- 2 PARTS- Required test program posted in the end*

1. Decoding Telephone Numbers

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

() to determine the letter-digit correspondences for your function.

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!

*Python Program- 2 PARTS- Required test program posted in the end* 1.

2. Displaying a Timeline From a File (6 points)

For this problem, you will develop two small functions that work together: one creates a Python dictionary from the contents of a text file, and the other displays the contents of that dictionary in a particular way.

Start by completing the loadEvents() function, which takes a string argument representing the name of a (plain text) data file. Each line of the file has the following format:

start-time end-time

label where start-time and end-time are integer values between 0 and 47 (inclusive), and start-time is always less than or equal to

end-time. label may consist of one or more words. All fields are separated by exactly one space. For example:

23 32 Meeting with Mary Brown

For each line in the file,

loadEvents()

should create a dictionary item where the key is equal to the

label and the value consists of a two-element list with the start-time and end-time values.

For example,

23 32 Meeting with Mary Brown

the event above would produce a key-value pair of the form:

"Meeting with Mary Brown" : [23, 32]

Decoding Telephone Numbers Some companies use letters to show their telephone numbers,

After processing the entire file, loadEvents() should return the dictionary that it created. Next, complete the timeline() function, which takes a dictionary as its only argument. This function displays each event from the dictionary, one per line, in any order. The first 48 columns of the line represent the duration of the day, broken up into half-hour increments. Columns that do not fall within the time span of the event (that is, between start-time and end-time) are filled with spaces; columns that are occupied by the event should be filled with asterisks instead. A short distance after the end of the 48 columns, print the event's label.

For example, given the event data:

in order to make the numbers easier to remember. For example, the

*Here is the required test skeleton that correlates to the programs in the question*

# Complete the functions that follow for this assignment

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()

Test Input Expected Output CALLHOME GETLOAN OMNIFORALL THISISAVERYLONGNAME 225-5466 438-5626 666-4367 844-7472

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!