Question: In python please :) You have to use the try... except syntax. A spelling alphabet (also known as a radiotelephone alphabet) is a set of
In python please :) You have to use the try... except syntax.


A spelling alphabet (also known as a radiotelephone alphabet) is a set of words used to stand for the letters of the alphabet in oral communication. Each word in the spelling alphabet typically replaces the name of the letter with which it starts. It is used to spell out words when speaking to someone not able to see the speaker, or when the audio channel is not clear. Consider the following dictionary which stores letters of an alphabet and the corresponding radio telephone words: dictionary = {'A':'Alfa', 'B': 'Bravo', 'c':'Charlie', 'D':'Delta', 'E':'Echo', 'F':'Foxtrot', 'G':'Golf', 'H':'Hotel', 'I' 'T':'Tango', 'U':'Uniform', 'V': 'Victor', 'W':'Whiskey','X':'X-ray','Y':'Yankee', 'Z':'Zulu','-':'Dash'} Write a function called get_telephone_alphabet(dictionary, letter) that takes such a dictionary and a letter as parameters. The function should return the word corresponding to the parameter letter. If the letter does not appear in the dictionary, then your function should return an error message to indicate that the particular letter is not available. If the parameter is an empty string, the function should return "ERROR: Invalid letter!". If the parameter is of an invalid type, the function should return "ERROR: Invalid input!". Note: you *must* use the try... except syntax and handle the KeyError in your solution. For example: Test Result print(get_telephone_alphabet(dictionary, 'A')) Alfa print(get_telephone_alphabet(dictionary, 'D')) Delta print(get_telephone_alphabet (dictionary, ',')) ERROR: ',' is not available. print(get_telephone_alphabet(dictionary , 123)) ERROR: Invalid input! print(get_telephone_alphabet (dictionary , "')) ERROR: Invalid letter! Consider the following function: def get_largest_even(filename): input_file = open(filename, 'r') lines = input_file.readlines() input_file.close() largest = -9998 for line in lines: items_list = line.split() for element in items_list: value = float(element) if value % 2 == 0 and value > largest: largest = value return largest The function takes a filename as a parameter and returns the largest even number in the file as a float. Modify the above function and use a try-except-else block to handle any exceptions that may occur. If the parameter filename is an empty string, the function should return "ERROR: Invalid filename!". If the file cannot be opened, the function should return "ERROR: The file 'xxx' does not exist." where XXX indicates the filename. You can assume that the minimum number in the file is -9998. If the file is empty the function returns -9998. If the file contains invalid values, the function should ignore those invalid values and continue to get the largest number in the file Note: remember to close the file properly if the file can be opened. You *must* use the try... except syntax and handle the FileNotFoundError in your solution. For example: Test Result print(get_largest_even ('numbers7.txt')) 6.0 print(get_largest_even('temp.txt')) ERROR: The file 'temp.txt' does not exist. print(get_largest_even ('empty1.txt')) -9998 print(get_largest_even('numbers_with_letters.txt')) 4.0 print(get_largest_even('')) ERROR: Invalid filename
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
