I'm just new to python and I was trying to write this program but there is a error and I'm unable to sort it out.
I have seen some other programs on internet for performing this, but all of them has some different logic.
Here the logic that i'm thinking is, if any of the letter in the string a is a vowel then I'll store in string b as it is and if its a consonant then I'll append three more letters to it.
I know I'm doing something wrong with the string but still I'm unable to figure it out.
The program is :-
a = ""
b = ""
def translate(a):
for i in a:
if (i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'):
b = b + i
else:
b = b + i
b = b + "o"
b = b + i
# b.append(" ")
# b[-3] = b[-1] = i
# b[-2] = 'o'
return b
a = input("Enter a string in English : ")
a = a.lower()
string = translate(a)
print("The Sring in spanish language is ", string)
Error in this program is : -
amitwebhero@AmitKali:~/python/python_home_work$ python3.5 5.py
Enter a string in English : amit upadhyay
Traceback (most recent call last):
File "5.py", line 19, in <module>
string = translate(a)
File "5.py", line 8, in translate
b = b + i
UnboundLocalError: local variable 'b' referenced before assignment
Thank's