Now that we have explored how to print things and comments, let's move on to some error debugging.
Errors can be classified into two types:
1. Compile-time("syntax errors".)
2.Run-time("glitches")
Compile-time errors are errors caused by not following the syntax of a program correctly. Syntax is the grammar of a programming language.
Let's look at two examples of compile-time errors, the first one is a typing error and the second is a syntax error.
Look at the below example. Can you find the error?
#The one with a typing errorprint("Hello World)This returns:
SyntaxError: EOL while scanning string literalThe error is the closing of the double quotations as you will see in 1.3. Don't panic if you don't understand how strings work.
On to the second one:
#With bad syntaxprint(Hello World)This returns:
SyntaxError: invalid syntaxThis is also the use of quotation marks.
So, Run-time errors are "glitches" in the program. For instance, it can be a security loophole, a logical error, or an infinite loop. Let's look at an example: (Psst! switch to 1.3 for better understanding of the program)
#A program with a run time errorprint(1/(1-1))This returns:
ZeroDivisionError: division by zeroimplying that there is an error at run-time, where there is an error because there is a glitch in the program as there is a zero division error.
1. Find the error and classify the type of error:
Hello Worldprint("Hello World")2.Find the error and classify the type of error:
#A glitchprint(1/(1*(2-2))