What is Python Translator explain with examples. When to use and how to use Translator in Python code.
Python Translator:
Option 1:
def translate(phrase):
===>translation = ""
===>for letter in phrase:
======>if letter in "AEIOUaeiou":
=========>translation = translation + "g"
======>else:
=========>translation = translation + letter
===>return translation
print(translate(input("Enter phrase: ")))
Result:
Enter phrase: dog
dgg
Option 2:
def translate(phrase):
===>translation = ""
===>for letter in phrase:
======>if letter.lower() in "aeiou":
=========>if letter.isupper():
============>translation = translation + "G"
=========>else:
============>translation = translation + "g"
======>else:
=========>translation = translation + letter
===>return translation
print(translate(input("Enter phrase: ")))
Result:
Enter phrase: DOG
DGG