Exception Handling | Sololearn: Learn to code for FREE!

+1

Exception Handling

why the code in the except block is not running. need help. link-https://code.sololearn.com/c178P8mqR6g6

12/1/2020 5:38:18 PM

Pratik Maity

5 Answers

New Answer

+6

There is a colon missing in the function definition at the end of the line: def find_number_even_or_odd(x, y): <--- this colon is missing!

+4

Lothar i think Pratik Maity may trying or meant "it's a syntax error, then why except Syntaxerror not handling that..?"

+1

Syntax error is special. When you run the program, the Python interpreter first checks if it even speaks the same language as you. So if your syntax doesn't make sense, you get a nice error, even before your code is evaluated. Therefore try-except doesn't work for SyntaxError. Read more on the topic here: https://realpython.com/invalid-syntax-python/ "When you run your Python code, the interpreter will first parse it to convert it into Python byte code, which it will then execute. The interpreter will find any invalid syntax in Python during this first stage of program execution, also known as the parsing stage. If the interpreter can’t parse your Python code successfully, then this means that you used invalid syntax somewhere in your code. The interpreter will attempt to show you where that error occurred."

0

I don't understand please explain

0

Jayakrishna, I think you understand what I mean