Page 464 - ComputerScience_Class_11
P. 464
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. Assertion (A): A missing closing parenthesis is a syntax run-time error in Python.
Reason (R): Parentheses are essential for function calls and grouping expressions and without them, Python cannot parse the
code correctly.
Ans. d. A is false but R is true.
2. Assertion (A): Console Input/Output (I/O) is essential for creating interactive and dynamic applications.
Reason (R): Console I/O allows the program to communicate with the user by accepting input and displaying output, enabling
user interaction.
Ans. a. Both A and R are true and R is the correct explanation of A.
3. Assertion (A): A NameError occurs when you try to use a variable that has not been defined.
Reason (R): A NameError can be fixed by ensuring that the variable is assigned a value before use.
Ans. a. Both A and R are true and R is the correct explanation of A.
F. Case study-based questions.
Zenat writes a Python program to calculate the total cost of two items using their prices and quantities. The program runs without
any error, but she is not getting the expected output.
price1 = int(input("Enter price of item 1: "))
qty1 = int(input("Enter quantity of item 1: "))
price2 = int(input("Enter price of item 2: "))
qty2 = int(input("Enter quantity of item 2: "))
total = (price1 + qty2) + (price2 + qty1)
print("Total cost is:", total)
Based on the given case, answer the following questions:
1. What type of error is present in the program?
a. Syntax Error b. Runtime Error
c. Logical Error d. Typing Error
2. Why does the program give the wrong result?
a. The program cannot run b. The quantities are multiplied with the wrong prices
c. The program divides by zero d. The input function is incorrect
Answers
1. c 2. b
G. Find the errors in the given code and write the correct code:
1. num = int(input("Enter a number: "))
print("Number is", end= )
print(num)
Ans. num = int(input("Enter a number: "))
print("Number is", end=" ")
print(num)
2. 1city = input("Enter your city name: ")
Print("I live in", city)
Ans. city = input("Enter your city name: ")
print("I live in", city)
462 Touchpad Computer Science (Ver. 3.0)-XI

