Question on for loop
Dave Angel
davea at davea.name
Mon Mar 4 08:36:45 EST 2013
On 03/04/2013 07:18 AM, newtopython wrote:
> Hi all,
>
> I'm super new to python, just fyi.
Welcome to the Python list.
>
> In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values in the lettersGuessed list that aren't in secretWord.
>
> What this code is doing is only checking the first character of secretWord and then returning True or False. How do I get it to iterate through ALL of the characters of secretWord?
>
> for character in secretWord:
> if character not in lettersGuessed:
> return True
> return False
>
Please post a complete sample when possible, and make sure you
copy/paste it, not just retype it and hope. As written, it'll throw an
exception when return is encountered. But before that, it'll complain
about the indentation of the return True.
Perhaps you have something like:
def has_some_behavior(secretWord, lettersGuessed):
for character in secretWord:
if character not in lettersGuessed:
return True
return False
If so, please copy the whole thing from your code, and explain just how
you call it (what arguments are passed), what it returned, and what's
wrong with that behavior.
--
DaveA
More information about the Python-list
mailing list