Wednesday

Chapter – 6: DEBUGGING PROGRAMS || Computer Science || Class 11

 

Chapter – 6: DEBUGGING PROGRAMS

 Short answer Type Questions

Q.1        What do you understand by Syntax errors and Semantics errors?

Ans: Syntax Errors: syntax error occur when rules of a programming language are misused i.e.

grammatical rule of Python is violated. e.g.

          X<-x*y

          if x=(x*y) etc.

        Semantics Errors: Semantics error occur when statements are not meaningful. e.g.

          x * y  =  z

this will result in a semantical eoor as an expression cannot come on the left side of an assignment operator.    

Q.2            Why are logical errors harder to locate?

Ans: in spite of logical errors presence, program executes without any problems but the output produced is not correct. Therefore, each and every statement of the program needs to be scanned and interpreted. Thus the logical errors are harder to locate. Q.3 What is an Exception?

Ans: Exception in general refers to some contradictory or unusual situation which can be encountered unexpectedly while executing the program. Unhandled exceptions will cause Python to halt execution.    

Q.4 Why is Exception Handling is required?

Ans: Unhandled exceptions will cause Python to halt execution.  The exception handling is ideal for processing exceptional situations in a controlled way so that program ends gracefully rather than abrupt crashing of the program.   

Q.5     What is the need for debugger tool?

Ans: Debugger tools are very useful especially if the code is big or the error is not very clear, it becomes very difficult to manually figure out the origin and cause of the problem. Debugger tools here prove very handy and useful. They show us the line by line execution and its result on variables interactively and help a programmer get to the root of the problem. Q.6 What are main error types? Which types are most dangerous and why?

Ans: Main error types are -  

          (i)Compile-time errors        (ii) Run-time errors     (iii) Logical errors

 Logical errors are most dangerous errors because these are most difficult to fix. The error is caused by a mistake in the program‘s logic. You won‘t get an error message, because no syntax or runtime error has occurred. You will have to find the problem on your own by reviewing all the relevant parts of your code – although some tools can flag suspicious code which looks like it could cause unexpected behaviour.

Q.7   What is a difference between an error and exception?

Ans:  Exception and Error: Exceptions are those which can be handled at the run time whereas errors cannot be handled. An exception is an Object of a type deriving from the System. Exception class. System Exception is thrown by the CLR (Common Language Runtime) when errors occur that are nonfatal and recoverable by user.

Q.8                   Name some common built-in exceptions in Python.

Ans: Some Common built-in Exceptions in Python are:

           (i) EOFError       (ii) IOError            (iii) NameError     (iv) IndexError    (v) ImportError

(vi) TypeError       (vii) ValueError (viii) ZeroDivisionError (ix) KeyError  Q.9 when does these exception occur?

(a)  Type Error                   (b) Index Error                  (c) Name Error

Ans: (a) Type Error: Raised when an operation or function is applied to an object of inappropriate

type. e.g. if you try to compute square-root of a string. 

(b)  Index Error: Raised when a sequence subscript or index is out of range e.g. from a string of length 4 if you try to read a value of index 4 or more. 

(c)  Name Error: Raised when an identifier name is not found. 

Q.10 What is debugging and code tracing?

Ans: Debugging involves correction of code so that the cause of errors is removed. I other words we can say that debugging means figure out the origin of error in code, fix the error code and review and rerun your code to ensure that the error is fixed.  

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.