将字符串隐藏为OTAN拼音字母的字典 [英] Dictionary that covert a string to OTAN phonetic alphabet
本文介绍了将字符串隐藏为OTAN拼音字母的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用户输入一个单词,该单词将转换为OTAN语音字母.
The user enter a word that which is converted to OTAN phonetic alphabet.
我必须使用字典,然后输入以下代码:
I have to use a dictionary and I put this code:
def otan():
dictionary = {'A':'Alpha', 'B':'Bravo','C':'Charlie', 'D':'Delta', 'E':'Echo', 'F':'Foxtrot', 'G':'Golf', 'I':'India', 'J':'Juliet', 'K':'Kilo', 'L':'Lima', 'M':'Mike', 'N':'November', 'O':'Oscar', 'P':'Papa', 'Q':'Quebec', 'R':'Romeo', 'S':'Sierra', 'T':'Tango', 'U':'Uniform', 'V':'Victor', 'W':'Whiskey', 'X':'Xray', 'Y':'Yankee', 'Z':'Zulu'}
input('Enter a word:')
otan()
我输入了一个代表GH的单词
I enter a word for exemple GH
但出现以下内容: NameError:未定义名称'GH'
我不明白该错误,因为字典中包含字母G和H
I dont understand the error because the dictionary includes the letter G and H
推荐答案
您需要分别访问每个键并使用 raw_input
,GH将是两个键而不是一个
You need to access each keys separately and use raw_input
, GH would be two keys not one
dictionary = {'A':'Alpha', 'B':'Bravo','C':'Charlie', 'D':'Delta', 'E':'Echo', 'F':'Foxtrot', 'G':'Golf',"H":"Hotel", 'I':'India', 'J':'Juliet', 'K':'Kilo', 'L':'Lima', 'M':'Mike', 'N':'November', 'O':'Oscar', 'P':'Papa', 'Q':'Quebec', 'R':'Romeo', 'S':'Sierra', 'T':'Tango', 'U':'Uniform', 'V':'Victor', 'W':'Whiskey', 'X':'Xray', 'Y':'Yankee', 'Z':'Zulu'}
inp = raw_input('Enter a word:')
print(" ".join(map(dictionary.get,inp)))
Enter a word:GH
Golf Hotel
这篇关于将字符串隐藏为OTAN拼音字母的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文