How to compare string characters with itself?
I want to remove vowels from a string and if a string has vowels consecutively then print the given string ex: map= mp feel = feel heal= heal
1/26/2022 12:28:28 PM
syed fahad
17 Answers
New Answera=str(input('enter the word')) vowels='aeiou' z='' n=0 for i in range(0,len(a)-1): n+=1 if (a[i] in vowels) and (a[i+1] in vowels): break if n == len(a)-1: for i in range(0,len(a)): if a[i] not in vowels: z+=a[i] print(z) if len(z)==0: print(a) Finally this worked
a=input() z="" vowels='aeiouAEIOU' for i in range(0,len(a)): if a[i] in vowels and (i+1<len(a) and a[i+1] in vowels): z=a break elif a[i] not in vowels: z+=a[i] print(z) """ further you can reduce if a[i] in vowels : if (i+1<len(a) and a[i+1] in vowels): z=a break else: z+=a[i] #can be done with single loop and #intput() to str convertion not needed """
use this and understand this . . . word = str((input("Enter a word: "))) print(word, "\n") VOWELS = ("aeiou") newWord ="" for letter in word: if letter.lower() not in VOWELS: newWord += letter print("Your word without vowels is: ",newWord )
a='Cat' z=[] vowels='aeiouAEIOU' for i in range(0,len(a)): if a[i]==a[i+1]: print(a) else: if a[i] not in vowels: z.append(a[i])
You can use a loop there, also have many ways.. Try to find a way yourself first And string characters can be extracted by indexes like s="str" print(s[0]) Hope it helps..
#as I+1 is out of range, take a condition as not test a[I+1], this will remove your error like : a='Cat' z=[] vowels='aeiouAEIOU' for i in range(0,len(a)): if i+1<len(a) and a[i]==a[i+1]: print(a) else: if a[i] not in vowels: z.append(a[i]) print(z) #but this is not work as two consecutive vowels.. syed fahad #use (a[I] in vowels and a[I] not in vowels] ), try am not checked now.. you can reply if not work. hope it helps....
import string alphabets = list(string.ascii_letters) letters = input('Enter Text: ') all = "" for letter in letters: if letter in alphabets: all += letter print (all)
Use Regex instead 1. Search if there are any consecutive vowels more than or equal to 2, then print the string. 2. Else we will search the vowel and replace with empty string in place of vowel. code : import re string = input() if re.search(r'[aeiou]{2, }', string): print(string) elif re.search(r'[aeiou]{1}', string): string = re.sub(r'[aeiou]{1}', '', string) print(string)