0

I'm currently attempting to find a way to change this for loop into a while loop, but i'm completely lost. i'm new to this whole python thing, so help would be really nice!

def ReturnConsonants(string):
    newStr=""
    vowels="aeiouAEIOU"
    for i in string:
        if not(i in vowels):
            newStr+=i
    return(newStr)
string=input("enter word: ")
print(ReturnConsonants(string))

2 Answers 2

1

For example:

j = 0
while j < len(string):
    i = string[j]
    if not (i in vowels):
        newStr += i
    j += 1
Sign up to request clarification or add additional context in comments.

Comments

0

Here is your code using while loop:

def ReturnConsonants(string):
    newStr=""
    vowels="aeiouAEIOU"
    i=0
    while i < len(string):
        if not(string[i] in vowels):
            newStr+=string[i]
        i=i+1
        return(newStr)
string=input("enter word: ")
print(ReturnConsonants(string))


You can do this so many way. Good Luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.