asdfasdf
asdfasdf

Reputation: 41

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)
        notes -= 1

    elif note is not rootNote and note not in patternNotes:
        patternNotes.append(note)
        notes -= 1

Upvotes: 1

Views: 322

Answers (3)

Joe
Joe

Reputation: 279

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.

Upvotes: 0

cwallenpoole
cwallenpoole

Reputation: 82028

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

Upvotes: 0

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.

Upvotes: 5

Related Questions