Example code for anti_vowel :)


#1


#example 1

def anti_vowel(text):
    vow = "aeiouAEIOU"
    word = ""
    for char in text:
        if (isvow(char) == False):
            word = word + char
    return word
    
def isvow(char):
    vowe = "aeiouAEIOU"
    for i in vowe:
        if (char == i):
            return True
    return False

#########example 2
def anti_vowel(text):
    vow = "aeiouAEIOU"
    word = ""
    for char in text:
        if ((char in vow) == False):
            word = word + char
    return word


#2

my example:

list1 = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
def anti_vowel(text):
list2 = []
list3 = []
for i in range(len(text)):
list2.append(text[i])
for i in range(len(text)):
for item in list1:
if item == text[i]:
list3.append(i)
count = 0
for i in range(len(list3)):
list2.pop(list3[i]-count)
count += 1
solution = "".join(list2)
return solution
print solution


#3

I thought I'd try something (which is pretty self-explanatory) from my knowledge of SQL: 'in'. I'm pretty sure we haven't touched on it before, but it worked like a charm.
Try simplifying a little without the use of multiple lists.

    if x in "abc" 
#or
    if x not in "abc"

SPOILER code below:

sentence = raw_input("Enter your thing: ")

def anti_vowel(text):
    no_vowels = ""
    for i in text:
        if i not in "aeiouAEIOU":
           no_vowels += i
    return no_vowels
        
print anti_vowel(sentence)

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.