syntax error on line: `if x.isupper() and not in y`
I'm getting "invalid syntax" errors pointing to the "in" statement. What's my mistake?
while(notes > 1):
note = choice(scale)
if note[0].isupper() and not in patternNotes:
patternNotes.append(note)
开发者_Python百科notes -= 1
elif note is not rootNote and note not in patternNotes:
patternNotes.append(note)
notes -= 1
You probably want
if note[0].isupper() and note not in patternNotes:
rather than
if note[0].isupper() and not in patternNotes:
Note the lacking note
in the second one.
It should be note[0].isupper() and note not in patternNotes:
(notice the second note
before not
)
After that your syntax is fine:
i = {}
j = {}
print i is not j and j not in {}
# False
Note that this is an infinite loop under certain conditions, like "note in patternNotes". Move the "notes -= 1" statement outside the if/elif and the problem is solved.
精彩评论