Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, November 29, 2012

Codecademy: For / else


#sample solution


fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape']

print 'You have...'
for f in fruits:
if f == 'tomato':
print 'A tomato is not a fruit!' #it actually is.
break
        #check if the word starts with a vowel
elif f[0] == "a" or f[0] == "e" or f[0] == "i" or f[0] == "o" or f[0] == "u":
print 'an', f
else:
print 'a', f
else:
print 'A fine selection of fruits!'

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts