+ 2
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
17 Answers
+ 7
a=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
+ 5
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
"""
+ 4
tried but getting index out of range error
+ 3
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 )
+ 2
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])
+ 1
you can use conditional statement ( if else)
+ 1
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..
+ 1
syed fahad show your attempt(save your code in code playground and share it's link here)
+ 1
yes Jayakrishna is also right you can use loop there..
+ 1
#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....
+ 1
imabhiiiiii🥱 this doesn't work with consecutive vowels
+ 1
import string
alphabets = list(string.ascii_letters)
letters = input('Enter Text: ')
all = ""
for letter in letters:
if letter in alphabets:
all += letter
print (all)
0
can you show me your code ?
0
please comment first line of code then print it
0
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)
0
كيف اكون هكر اخلقي
0
Hi