- 1

Not getting the desired output whats the mistake?

Program to print word without vowels:- Code:- word = input() x=[i for i in word if(i!='a','e','i','o','u')] print(x) Above is the code I wrote but not getting desired output need help.

15th Sep 2021, 12:53 PM
Aniket Singh
Aniket Singh - avatar
12 Réponses
+ 2
Hi ANIKET! I suggest you to use and operator instead. Because, or operator evaluates true(means 1), if any condition is satisfied. For example, if i != a is a true statement then your entire condition will be true even if i is equal to e or other vowels. When you're trying to connect many conditions using logical operators, you have to compare all characters(here vowels) separately. Here it is your working code. word = input() x=[i for i in word if i!='a' and i != 'e' and i != 'i' and i != 'o' and i != 'u'] print(x)
15th Sep 2021, 2:19 PM
Python Learner
Python Learner - avatar
+ 1
Thanks for the help
15th Sep 2021, 1:05 PM
Aniket Singh
Aniket Singh - avatar
+ 1
✩✮★✮✩ I think it may more better answer if you will explain your code. I think you are trying to make a program which collect consonants of a word or sentence. word = input().lower() #Data given by user is stored in variable word ,in lower case x = [i for i in words if i not in "aeiou"] #it will iterate through all letter of word append in list if letter is not available in string a, e, i, o or u print("".join(x)) #x is list, if you want to make it display as string then use .join() it will join the list and make it str [ Code by star star .... star ] https://code.sololearn.com/cVX9E3fG3RoC/?ref=app ANYKET:) See it!
15th Sep 2021, 1:13 PM
Abhiyantā
Abhiyantā - avatar
+ 1
Thanks for the help Rishav Tiwari 🔥🔥
15th Sep 2021, 1:27 PM
Aniket Singh
Aniket Singh - avatar
+ 1
ANYKET:) for that just print x, insted of using join() simple! ;) All The Best! 👍
15th Sep 2021, 3:18 PM
Abhiyantā
Abhiyantā - avatar
+ 1
Thankyou guys :)
15th Sep 2021, 3:19 PM
Aniket Singh
Aniket Singh - avatar
0
Oops it's not working either
15th Sep 2021, 1:09 PM
Aniket Singh
Aniket Singh - avatar
0
And what is I need those words in list ?
15th Sep 2021, 1:36 PM
Aniket Singh
Aniket Singh - avatar
0
Do I have to split in such case?
15th Sep 2021, 1:36 PM
Aniket Singh
Aniket Singh - avatar
0
Given a word as input, output a list, containing only the letters of the word that are not vowels. The vowels are a, e, i, o, u. Sample Input awesome Sample Output ['w', 's', 'm'] See this is the exact question
15th Sep 2021, 1:39 PM
Aniket Singh
Aniket Singh - avatar
15th Sep 2021, 2:25 PM
Aniket Singh
Aniket Singh - avatar
0
Thanks for sharing, very helpful https://patronsurveys.com/
13th Oct 2022, 12:16 PM
Damon prett
Damon prett - avatar