-3

I am all new to programming and have to develop a simple script that converts a word into NATO-language. I have figured out (through Google) how to convert the word to NATO, but it also returns 'None'? Why does it do that?

def textToNato(plainText):
    
    d =  {
        'A': 'Alpha',  'B': 'Bravo',   'C': 'Charlie',
        'D': 'Delta',  'E': 'Echo',    'F': 'Foxtrot',
        'G': 'Golf',   'H': 'Hotel',   'I': 'India',
        'J': 'Juliett','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': 'X-ray',
        'Y': 'Yankee', 'Z': 'Zulu'}
    natoText = print('-'.join([d[x] for x in [*plainText.upper()]]))
    return natoText
Michael Szczesny
  • 4,911
  • 5
  • 15
  • 32
Polle
  • 1
  • FYI it's not a language. Its just spelling/phonetic alphabet (NATO phonetic alphabet or the ICAO phonetic alphabet). – Marcin Orlowski Oct 21 '20 at 07:42
  • Don't `print` the result inside the function, do it afterwards: `print(textToNato('OMGWTFLOL'))`. (It is a good idea in general to separate data processing from input and output.) – molbdnilo Oct 21 '20 at 07:43

1 Answers1

2

natoText = print(...) Print returns None, that's the reason behind the issue. What you should do is

natoText = '-'.join([d[x] for x in plainText.upper()])
print (natoText) #if you need to print here
return natoText
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24