-6

I'm new to python and was working on a simple password cracker for practice with lists and dictionaries. Half way thru my test program I ran into this error.

PS E:\python_projects> python test.py
  File "test.py", line 9
    global counter += 1
                    ^
SyntaxError: invalid syntax

Here is the code...

maxChar = 4
counter = 0
alph = ['A','B','C','D','E','F','G']
passCheck = []
password = 'f'
password = str(password.lower())

def loopTest():
    global counter += 1

    if counter <= maxChar:
        loopTest()  #Nests loops

    else:
        for letter in alph:     #scans letters
            passCheck[0] = letter

            if passCheck == password:   #checks password
                print 'found password: ' + passCheck

            else:
                print passCheck

loopTest()

print 'Debug.'
print counter

there may be other errors and that's fine but I don't understand why I'm getting hung up on a += that I thought I understood, anyway thanks for looking!

Sam
  • 11
  • 1
  • 1

1 Answers1

1

You mixed two different ideas in Python, a "global statement" and an "augmented assignment statement."

A "global statement" has a very simple syntax:

"global" identifier ("," identifier)*

No expression is allowed in a global statement.

Perhaps you wanted to say:

global counter
counter += 1
Robᵩ
  • 163,533
  • 20
  • 239
  • 308