Help me to fix the error?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help me to fix the error??

a = input() j = 0 for i in a: if i != 'a' and i != 'e' and i != 'i' and i != 'o' and i != 'u': i = "|"+i else: i = i+"|" print(a)

5th Aug 2021, 8:29 AM
Shahir
Shahir - avatar
10 Answers
+ 3
Shahir , if you really have a problem, we need some more details from you: ▪︎give a clear and complete description about your task ▪︎if there are error messages please post them here ▪︎give at least one sample with input data and the expected output ▪︎to be able to find out the issues you have, we need to see your code     => please put your code in playground, save it there and post a link to it here. thanks for your understanding!
5th Aug 2021, 10:30 AM
Lothar
Lothar - avatar
+ 1
Almost same code little above.
5th Aug 2021, 9:05 AM
Shadoff
Shadoff - avatar
+ 1
If I enter a vowel then it should output that vowel along with "|" Example: Input:a Output:a| Input:s Output:|s
5th Aug 2021, 11:09 AM
Shahir
Shahir - avatar
+ 1
Shahir , still not clear enough. please answer this questions: ▪︎if the input is a single char like "a" or "f" => output :...... ▪︎if the input is a word or a sentence like "python is cool!" => output :......
5th Aug 2021, 12:44 PM
Lothar
Lothar - avatar
+ 1
If input is "a" As "a" is a vowel it should print like "a|" If input is "f" As "f" is not a vowel it should print like "|f" And if you enter a string then Input:lothar Output:|l o| |t |h a| |r As "l" is not a vowel so it prints "|l" And as "o" is vowel so it prints "o|" ....... Hope you understand Ask me if you don't understand
5th Aug 2021, 12:50 PM
Shahir
Shahir - avatar
+ 1
vow="aeiou" x = "hello world" x = x.lower() z = '' for i in x: if i in vow: z+="i+"|" elif i.isalpha() and i not in vow: z+="|"+i else: z+=i print(z)
5th Aug 2021, 2:34 PM
Shadoff
Shadoff - avatar
+ 1
1.You loop through the string, and it is bad practice to change item(s) of list during iteration. 2. string is immutable. So trying assign new value to any item of string causes error.
5th Aug 2021, 2:53 PM
Shadoff
Shadoff - avatar
+ 1
Import re a=input(‘enter a letter:’) pattern=r”[a|o|u|i|e]” match=re.match(pattern,a) if match: print(f”{a}|”) else: print(f“|{a}”)
6th Aug 2021, 10:05 PM
Tea
Tea - avatar
0
Thanks but why my code isn't working properly??
5th Aug 2021, 2:37 PM
Shahir
Shahir - avatar
0
Shahir You haven't changed the string at all. Simply changing the value of iterable won't make any change in strings in python. Just use .replace method just as I did. Hope it's clear to you... https://code.sololearn.com/cdAfzq5X47tj/?ref=app
6th Aug 2021, 11:53 AM
Muhammed Shafi
Muhammed Shafi - avatar