Page 486 - ComputerScience_Class_11
P. 486
7. Define the following:
a. Simple Statement
b. Multiline Statement
c. Multiple Statement
Ans. a. A simple statement in Python is a statement that is written in a single line and completed by pressing the Enter key. Each
simple statement performs one action and is written on a new line.
b. A multiline statement is a statement that is written across two or more lines instead of a single line. It is used when the code
is too long to fit comfortably on one line. Multiline statements make the program more readable and organized.
c. A multiple statement in Python refers to writing two or more statements on the same line. This is done by separating each
statement with a semicolon (;). Normally, Python executes one statement per line. However, when we want to write short
statements together on a single line, we can use semicolons to separate them.
8. What is meant by type conversion in Python?
Ans. Type conversion in Python is the process of changing a value from one data type to another, ensuring that operations and
calculations work correctly. It allows a value to be treated as a different data type so that operations can be performed correctly.
For example, you might convert an integer to a float or a string to an integer. Python supports two main types of type conversion:
• Implicit Conversion
• Explicit Conversion
D. Higher Order Thinking Skills (HOTS)
1. A program is designed to calculate the total cost of a shopping cart. The program uses the following conditions:
• Apply a 10% discount if the total cost is greater than $100, using the condition total_cost > 100.
• If the discount is applied, the new total is calculated with total_cost -= total_cost * 0.10.
However, the programmer accidentally uses total_cost < 100 instead of total_cost > 100. What would happen if the total cost is
$120?
Ans. Using total_cost < 100 will incorrectly apply the discount for total costs below $100. In this case, since $120 is not less than $100,
no discount will be applied. The programmer should use total_cost > 100 to correctly apply the discount for larger totals.
2. A program is checking if a number is both divisible by 4 and 6 using the logical and operator. The condition is written as:
num % 4 == 0 and num % 6 == 0.
What would happen if the programmer mistakenly uses the or operator instead? How would this affect the result when the num-
ber is 12?
Ans. Using the or operator would return True if the number is divisible by either 4 or 6. Since 12 is divisible by both 4 and 6, the result
would still be True with or, but the intended logic is for both conditions to be true. Using and ensures that both conditions must
be met.
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): An operator is used to perform a specific operation on one or more values, called operands and is essential for
performing calculations, comparisons, logical decisions and assignments in Python.
Reason (R): Operators are the basic building blocks for writing Python programs, enabling various operations like mathematical
calculations, data manipulation and logical decisions.
Ans. a. Both A and R are true and R is the correct explanation of A.
2. Assertion (A): A simple statement in Python is written in a single line and completed by pressing the Enter key.
Reason (R): Each simple statement performs multiple actions and can be written on the same line for efficiency.
Ans. c. A is true but R is false.
3. Assertion (A): Operator precedence refers to the order in which Python evaluates different operators in an expression.
Reason (R): If two operators have the same precedence, the expression is evaluated according to associativity (usually left to
right).
Ans. b. Both A and R are true but R is not the correct explanation of A.
484 Touchpad Computer Science (Ver. 3.0)-XI

