Debugging Programs in Python Class 11 computer science of Sumita Arora according to the latest CBSE syllabus solved assignment Questions and Answers.
Q.1. Compile-time are main error types ? Which types are most dangerous and why?
Answer:
Syntax Error, run-time errors and logical Error are main types of Errors. Logical type is most dangerous as they are hard to find and fix them.
Q.2. Correct any false statements :
(a) Compile-time errors are usually easier to detect and to correct than run-time errors
(b) Logically errors can usually be detected by the compiler.
Answer:
(a) The statement is correct.
(b) The statement is incorrect. The correct statement should be:
Logical errors cannot be detected by the compiler
Q.3.Differentiate between a syntax error and a semantics error.
Answer:
Syntax error – Syntax errors occurs when the rules of the programming language are violated.
Example:
x = false
Semantics error- Semantic errors occur when the statement are not meaningful.
Example:
x * y = z
Q.4.Differentiate between a syntax error and a logical error in a program . When is each type of error likely to be found?
Answer:
Syntax Error | Logical Error |
---|---|
Syntax Errors occur when we violate the rules of writing the statements of the programming language. | Logical Errors occur due to our mistakes in programming logic. |
Program fails to compile and execute. | Program compiles and executes but doesn’t give the desired output. |
Syntax Errors are caught by the compiler. | Logical errors need to be found and corrected by people working on the program. |
Syntax errors are found at compile type whereas Logical errors are found when the program starts executing.
Q.5.What is the difference between an error and exception?
Answer: When Error occur the program is stopped and user have the control of the program but when exception occur program go on and on and user have no control over it.
Q.6. How can you handle an exception in Python? Write sample code to illustrate it.
Answer:
x=1
y=0
c=x/y #here exception occurs.
We can handle exception by putting if condition that y cannot be zero , type other number.
Q.7. Name some common built-in exceptions in python.
Answer:
Name Error
Type Error
Key Error
Q.8. When does these exceptions occur?
(a) Type Error
(b)Index Error
(c)Name Error
Answer:
(a) Division of a string by an integer type. Use of different type on different not allowed types.
(b) Accessing a index that is invalid.
(c) Accessing a invalid variable or function.
Q.9. What is debugging and code tracing ?
Answer:
Debug is going through the code flow during run time where as tracing is giving details of execution plan, process timing details.
Q.10. What are these pdb commands used for?
(a)b (b)cl (c) 1 (d) h (e)n (f) P
b: Break
n:Execute the current line
p:print value of the variable
h: help command
cl: clear all the breakpoints at this line
l:List List source code for the current file.
Thanks for reading Debugging Programs in Python Class 11 Assignment. More of such assignment are here.
For more solved assignments- Click here
For practical file question – Click here