def change(sentence):
vowel = {'a':'1','e':'2','i':'3','o':'4','u':'5'}
final_sentence = ''
for s in sentence:
s = s.lower()
if s not in vowel:
final_sentence = final_sentence + s + 'a'
else:
for v in vowel:
if s == v:
s = vowel[v]
final_sentence += s
return final_sentence
Hi all, above is my code. What i am trying to achieve is a simple game where a sentence is passed into a function and every vowel (a,e,i,o,u) found in the sentence should be replaced with corresponding numbers(1,2,3,4,5) and concatenated with my variable called final_sentence. ALso every consonant should be concatenated with the string 'a' and then concatenated with my final_sentence variable. Finally the final_sentence variable should be returned. The string is passed into the function was 'I love you' and the corresponding result should be "3 la4va2 ya45" but that is not the case. Apparently, python sees the empty strings between words as characters and is now concatenating the string 'a' to them. How do i stop that?
see my output below
'3 ala4va2 aya45'