What is Python Translator explain with examples. When to use and how to use Translator in Python code.

Python for BEGINNERS and DUMMIES

Reusable Define Function with Return


Python 2D Lists and Nested Loops Examples


Python exception handling using
try except with examples


Python For Loop condition with examples


Python while condition with examples


Python if elif else logical condition


Python Tuples vs List


Python Translator with Examples


Python List Functions with Examples


Data Structures and Data Types


Python Exponent Function with examples


Python dictionary with examples


Variables, Expressions & Statements


List of 'Reserved Words' in Python


Boolean Expressions &
Comparison Operators

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