Issue
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
I dont undertand why translation = translation + "G".Can someone help me
Solution
The translation = translation + "G"
adds 'G' to the existing string translation
Eg. if translation = "Hi"
then translation = translation + "G"
comes out to be "Hi"+"G" which is "HiG"
All that I can tell is what this code in words. If you could tell me what you wanted the output to be I could have helped you more.
So what the code does is that it takes a phrase/sentence and it replaces all vowels with a g (Capital G if vowel is capital or small g if vowel is small).
Eg. phrase="Welcome to Overflow"
Output -> translation="Wglcgmg tg Gvgrflgw"
Answered By - Gagan G Answer Checked By - Pedro (WPSolving Volunteer)