Python 3 syntax error invalid syntax

Python 3 syntax error invalid syntax

if_name_ == _main_:
    a = input(Enter a number: )
    multi_table(float(a))

should be :

if __name__ == __main__:
    a = input(Enter a number: )
    multi_table(float(a))

Notice that both variable __name__ and __main__ has two underscores around them and that there must be a space between the if keyword and the start of the condition.

As @Maroun Maroun said right, it has to be if __name__ == __main__ . But you wont need it. Just write it at the bottom :

Multiplication Table

def multi_table(a):
    for i in range(1,16):
        print( {0} x {1} = {2} .format(a, i, a*i))

a = input(Enter a number: )
multi_table(float(a))

Should work, too.

EDIT: In the official docs :

https://docs.python.org/3/library/main.html

if __name__ == __main__:

Python 3 syntax error invalid syntax

It is likely due to a mismatched paranthesis prior to the if statement. Check if all your (s are matched by a closing ).

Leave a Reply

Your email address will not be published. Required fields are marked *