Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to solve this problem by python:

If a word contains two consecutive vowels(a,e,i,o,u,y), you must delete the second letter and then print the word.

I wrote this code, and I know that it is not completely correct, There are things that don't make sense.

Although it gives me the required result, I find that it is incorrect, because there are too many nested loops.

I want a better and easier code please.

What I have tried:

def Convert(string):
	word = ["","","",""]
	word[:0] = string
	return word

word1 = str(input("Enter the word: ")).lower()
word = Convert(word1)
vowels = ["a","e","i","o","u","y"]
y = []

for i in range(1,len(word)-4):
  for j in range(5,len(vowels)):
    for x in range(6):
      for v in range(6):
       if word[i] == vowels[j-x] and word[i-1] == vowels[j-v]:                                                          
          word.remove(word[i])                                    
          print("".join(word))
          y.append("".join(word))
          break

if len(y)==0:
    print(word1)

<pre lang="Python"><pre lang="Python"><pre lang="Python">
Posted
Updated 11-Jan-23 13:27pm

Quote:
I want a better and easier code please.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Rama Aljelani 16-Dec-22 6:17am    
I did not publish the problem and ask about its solution from scratch, I posted the question and attached my solution for it, I posted what I have tried, I am asking if my solution is correct or not, as a begginer in programming, I am asking if there is a way to write it in a better way, maybe the question written at the beginning is not appropriate, but If you completed reading to the end, you would have understood what I am asking for, you would have seen that I attached my code.
And for your information, this is not an assingment I have to hand in, or a job that I get money for, and if it is anm assingment, then I can hand over this code, as it achieves what is required! This is just a practice for me to get better at programming
OriginalGriff 16-Dec-22 6:32am    
I refer you to the quote from your "question":
Quote:I want a better and easier code please.
Now, does that sound to you like "I want full code" or "I need help"?
Because to me it sounds like "I found this on the internet, but it's a bit rubbish and I won't get a good grade if I hand this in, so give me a better solution I can say I wrote".

You won't get "better at programming" by getting others to give you code: just like any other skill you improve by doing it yourself. You can watch as much of the Tour de France as you like, but you still won't be able to ride a bicycle!
Rama Aljelani 16-Dec-22 7:07am    
I'm not going to argue with you, thanks for your bad thinking, I got what I want elsewhere, there are good people who helped me, it wasn't hard, they just guided me to use something I know, but I didn't think to use, and some of them showed me a new way, they taught me something new.
Anyway, thanks again for nothing, you're not the only one who has an answer to my question
How about this:
Python
vowels = 'aeiou'
word = input('Enter your word: ')
for x in range(len(word) - 1):
    if word[x] in vowels and word[x] == word[x + 1]:
        newword = word[:x] + word[x+1:]
        print(word, 'becomes:', newword)
 
Share this answer
 
Comments
Rama Aljelani 16-Dec-22 13:36pm    
thank you
Not sure what should happen with more than two consecutive vowels but what about
word = input('Enter your word: ')

out = ''
last = '.'

vowels = 'aeiouyAEIOUY'

for letter in word:
    if letter in vowels:
        if last not in vowels:
            out += letter
    else:
        out += letter
    last = letter

print(out)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900