Search code examples
pythonfor-loopnumberssyntax-errorequals

Don't understand the error message : Invalid syntax in for statement


I am writing a very simple program to output the 0-10 in numbers using a for loop. However it comes up with a syntax error when I click run, highlighting in red the "=" in the 8th line. I don't understand why it is wrong? I am using python 3.5.2 in idle mode.

def numbers():
    print ("This program will count to ten, just you wait...")
    import time
    time.sleep(1)
    print ("\n\nLiterally wait I just need to remember base 10 because I 
    only work in binary!")
    time.sleep(4)
    int(counter) = 0
    for counter <**=** 9: 
    print ("\n" + counter)
    counter =  counter + 1

    print ("\n\nAnd there you go. Told you I could do it. Goodbye :) ")
    time.sleep(2)
    exit()

numbers()

Solution

  • Try it like this:

    def numbers():
        print ("This program will count to ten, just you wait...")
        import time
        time.sleep(1)
        print ("\n\nLiterally wait I just need to remember base 10 because I only work in binary!")
        time.sleep(4)
        for i in range(1, 10): #11 if you want 10 to be printed
            print i
    
        print ("\n\nAnd there you go. Told you I could do it. Goodbye :) ")
        time.sleep(2)