A confusing point


#1

def anti_vowel(text):
a=""
for i in range(len(text)):
if text[i]!= ‘a’ and text[i]!= ‘A’ and text[i]!= ‘e’ and text[i]!= ‘E’ and text[i]!= ‘i’ and text[i]!= ‘I’ and text[i]!= ‘o’ and text[i]!= ‘O’ and text[i]!= ‘u’ and text[i]!= ‘U’ :
a=a+text[i]
print a
else:
a=a
print a
return a
At first, I used “if text[i]=! ‘a’ or ‘A’ or…” and obviously it did not work. It took me several minutes to get it clear.


#2

and your question is why if text[i] != 'a' or 'A' didn’t work?

this is best explained with a joke called:

A wife sends her programmer husband to the grocery store for a loaf of bread…

On his way out she says “and if they have eggs, get a dozen”. The programmer husband returns home with 12 loaves of bread…

this is literally how computers thinks, which is why you experienced problems with your code initialize, or 'A' simply means: evaluate if A is true, given we didn’t compare it with anything.


#3

def anti_vowel(text):
a=’‘
for i in text:
for j in ‘aeiouAEIOU’:
if i==j:
i=’’
#break
a=a+i
return a
print anti_vowel(‘abeihu’)


#4

using in is certainly a better option indeed :slight_smile: