samedi 25 juillet 2015

Python: Looping If Statement

friends = ["Bob","Mike","Ana","Tim","Dog"]

def is_buddy(name):

    for friend in friends:
        print friend
        if friend == name:
            return True
        else:
            return

print (is_buddy('Tim'))

What is the problem here? Why do I get False if I put in "Tim" or anyone else other than Bob?

Aucun commentaire:

Enregistrer un commentaire