• Register
1 vote
1.2k views

Problem:

I’ve written a basic python program and trying to compile and run it. Unfortunately, the program is not working for me. find the attached snippet below of my program:

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

if_name_ == '_main_':
    n = input('Enter a number to multiply: ')
    multiple_table(float(n))

As you can see, the above program is supposed to create multiplication tables. The program should prompt a number from the user and find the multiplication table in the range. But, the problem is encountered on the line if _name_ == _main_ and I missed a (:) colon first time. Then I went to google and fix the problem by putting a colon after that line. I am still having the same issue on the same line with the same SyntaxError. I am used to writing codes in python 2. So, python-3 is pretty much new to me. I smell something very silly in that line but couldn’t figure out the problem. Could you please give a review into my codes and find out the bug?

I am looking forward to having a legit solution from you. Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

Hello Gavin,

Have a look at that line again. What you have written? It has to be

if __name__ == "__main__":

with a double underscore (_’_) but,

Not like this:

if_name_ == '_main_':

Change it to the correct form. It should run absolutely fine. Other operations are in good form. You can check the python 3.8 documentation from HERE.

I hope you got the sneaky point. So, save your day as your own  laughlaugh

Good Day!

13 9 6
94,260 points

Related questions

0 votes
2 answers 708 views
708 views
Problem: Hello guys, I am running this code in visual code but dont know why the error ic coming can you please check the error of if__name__ ==__main__invalid syntax. def main(): generateRandomNumbers() def generateRandomNumbers(): print ('Test') si_ze = 0 nameLength=0 ... == "__main__" main() Getting Syntax error if name == main ^ SyntaxError: invalid syntax Process finished with exit code 1
asked Jun 9, 2020 Gavin 15.3k points
0 votes
1 answer 35 views
35 views
Problem: Before executing code, Python interpreter reads source file and define few special variables/global variables. How to python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value &ldquo ... module, __name__ will be set to the module’s name. Module’s name is available as value to __name__ global variable?
asked Jan 11 Mashhoodch 13k points
0 votes
1 answer 107 views
107 views
Problem: How to I Solve this: %matplotlib inline ^ syntaxerror: invalid syntax HELP! I need help understanding this: %matplotlib inline ^ syntaxerror: invalid syntax Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 3 Mashhoodch 13k points
1 vote
1 answer 67 views
67 views
Problem: Hello guys, While solving basic condition problem in python I am trying to implement the below logic but don't know python is throwing error, the invalid syntax for no reason,below is the code. day = int(input("Enter the day of week:")) vacation = (input("Enter is vacation? [True| ... 00") else: if day == 0 or day == 6: print("Alarm is off") elif: print("10:00") Dont know what is wrong.
asked Jun 7, 2020 Gavin 15.3k points
0 votes
1 answer 7 views
7 views
Problem: How can I fix this please ? Python class __name__
asked Mar 21 PkGuy 23.5k points
0 votes
1 answer 8 views
8 views
Problem: If anyone know about python then, please answer me. Can anyone here who help me about it?
asked Mar 21 niyatiry 3.9k points
0 votes
1 answer 10 views
10 views
Problem: How to fix this: how to solve syntax error when using command line in python
asked Mar 19 Wafa Abu Yousef 6.1k points
0 votes
2 answers 174 views
174 views
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains print("Hello.")), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have ... but when I do so I get this: File "<stdin>", line 1 python test.py ^ SyntaxError: invalid syntax What is wrong? Thanks in advance!
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 11 views
11 views
Problem: I am developing a web in Ubuntu using django. Everything works normal. Now, I want to change my computer which use Windows. When I try to runserver, it gives: E:\DEGNet>py manage.py runserver File "manage.py", line 14 ) from exc ^ ... " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv)
asked May 3 jamuna1 30.2k points
1 vote
1 answer 7 views
7 views
Problem: So as I am new to programming. therefore need expert opinion on this. Python multiple statements found while compiling a single statement.
asked Apr 20 PkGuy 23.5k points