티스토리 뷰

nato_phonetic_alphabet.csv
0.00MB

import pandas

#TODO 1. using csv file, Create a dictionary in this format like:
#{"A": "Alfa", "B": "Bravo"}

data = pandas.read_csv("./nato_phonetic_alphabet.csv")
data_dict_comprehension = { row.letter:row.code
    for (index,row) in data.iterrows()
    }

#TODO 2. Create a list of the phonetic code words from a word that the user inputs.

def phonetic():
    word = input("Enter a word: ").upper()
    try:
        phonetic_word_lists = [ data_dict_comprehension[letter] for letter in word ]
    except KeyError:
        print("Sorry, only letters in the alphabet please.  ")
        phonetic()
    else:
        print(phonetic_word_lists)

phonetic()

-------------------------------

Enter a word: 123
Sorry, only letters in the alphabet please.  
Enter a word: 1w
Sorry, only letters in the alphabet please.  
Enter a word: fdsaf5
Sorry, only letters in the alphabet please.  
Enter a word: i love you
Sorry, only letters in the alphabet please.  
Enter a word: iloveyou
['India', 'Lima', 'Oscar', 'Victor', 'Echo', 'Yankee', 'Oscar', 'Uniform']

Process finished with exit code 0

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함