Page 463 - ComputerScience_Class_11
P. 463
C. Answer the following questions:
1. What is meant by Input/Output or I/O in programming?
Ans. Input/Output or I/O is the process by which a program communicates with the outside world.
2. Why is a Command Line Interface considered a powerful tool?
Ans. A Command Line Interface is considered powerful because it is used to build applications from simple scripts to complex software.
3. In the syntax variable = input(prompt), what does the variable represent?
Ans. The variable stores the value entered by the user.
4. What is the purpose of the print() function?
Ans. print() is commonly used for showing results of computations, user messages or debugging data.
5. Why are error messages important in Python?
Ans. Python's error messages provide a traceback, which shows the error type, a description and the exact line number where the
error occurred.
6. List the common causes of syntax errors.
Ans. Common causes of syntax errors are:
• Forgetting a colon (:) at the end of an if, for, while or def statement.
• Missing or mismatched parentheses (), brackets [] or quotes "".
• Incorrect indentation (mixing tabs and spaces or inconsistent indentation levels).
• Misspelling Python keywords (e.g., writing whille instead of while).
7. Define run-time errors in Python.
Ans. Run-time errors, also known as exceptions, occur while the program is running. The syntax of the code is correct, so the program
starts, but during execution, something unexpected happens that forces the program to stop. These errors are often caused by
user input or unforeseen states.
8. Explain the purpose of the try...except block in Python and its process for handling runtime errors.
Ans. To prevent runtime errors from crashing your program, Python provides a way to catch and handle them. This is done using the
try...except block.
This is the process of how it works:
• The code that might cause an error is placed inside the try block.
• If no error occurs, the except block is skipped.
• If an error occurs in the try block, the rest of the try block is immediately skipped and the code inside the except block is
executed. This allows the program to recover and continue running.
D. Higher Order Thinking Skills (HOTS)
1. A programmer wrote the following code to calculate the area of a rectangle:
length = 10
breadth = 5
area = length + breadth
print("Area of rectangle is:", area)
The output is 15, but the programmer expected the result to be 50.
Ans. The logical error is that the program adds the length and breadth instead of multiplying them. The area of a rectangle is calculated
by multiplying length and breadth. The correct code should be:
area = length * breadth
This will correctly calculate the area of the rectangle as 50.
2. Explain how Python error messages help programmers identify problems in their programs.
Ans. Python error messages provide a traceback, which contains detailed information about the error. The traceback indicates the type
of error, a description of the problem and the exact line number where the error occurred.
This information helps programmers locate the mistake in the code quickly. By analysing the traceback, programmers can
understand why the error occurred and modify the program accordingly.
Data Processing in Python 461

