0% found this document useful (0 votes)
12 views4 pages

Chapter-6 Control Statements in Python (EXERCISE)

The document is a coaching material focused on control statements in Python, covering topics such as operator precedence, conditional statements, and the use of operators. It includes fill-in-the-blank exercises, true/false questions, multiple-choice questions, competency-based questions, and detailed answers about various programming concepts. The material aims to enhance academic excellence in computer science through structured learning and practice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Chapter-6 Control Statements in Python (EXERCISE)

The document is a coaching material focused on control statements in Python, covering topics such as operator precedence, conditional statements, and the use of operators. It includes fill-in-the-blank exercises, true/false questions, multiple-choice questions, competency-based questions, and detailed answers about various programming concepts. The material aims to enhance academic excellence in computer science through structured learning and practice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PIYASHA BHATTACHARJEE’S COACHING

Sanskrit | Maths | Science | Computer | English


Online Tutor for Batches and 1:1 focus for academic excellence

Computer
Chapter- 6

Control Statements in Python


A.​Fill in the Blanks.

1.​ The order in which the operators are evaluated is called precedence
of operators.
2.​ The “+” operator is used to concatenate or join two or more strings.
3.​ In python, the flow of execution is altered by the use of the control
statements.
4.​ The if-else control structure is used when either of the two different
actions is to be performed depending upon the result of the condition.
5.​ Boolean operators evaluate one of the two states, either True or
False.

B. State True or False.

1.​ An operator does not need any operand to perform operations.


⇒ False

2.​ Exponential operator is used to calculate the power of one number to


the other.
⇒ True

3.​ Higher precedence operators are operated before the lower


precedence operators.
⇒ True

4.​ The ‘if-elif-else’ statement is used when you need to evaluate only one
condition.
⇒ False

5.​ Iterative statements are also known as looping statements.


⇒ True

1
PIYASHA BHATTACHARJEE’S COACHING
Sanskrit | Maths | Science | Computer | English
Online Tutor for Batches and 1:1 focus for academic excellence

C. Select the correct option.

1.​ The values on which the operators work are known as Operands.
a. Operands b. Data c. Numbers

2.​ The expression 14//3 results to 4.


a.​ 9 b. 4 c. 5

3. In which construct are the statements in a program executed in a


sequential manner one after the other with no possibility of branching
off to another action ? Sequential
a.​ Conditional b. Sequential c. Iterative

4. Which block of statements will be executed if the conditional


expression evaluates to false in the ‘if…else’ construct ? else
a.​ else b. if c. Both a and b

5. The expression 5**2 results to 25.


a.​ 7 b. 25 c. 10

D. Competency- based question.


Sumit is converting a decimal number to binary number. He needs to
calculate the remainder in each step. Which operator would you suggest
him to use for his task ?

⇒ While converting a decimal number to a binary number, Sumit needs


to calculate the remainder at each step of division. For this task, he
should use the modulus operator (%). This operator gives the remainder
when one number is divided by another. In decimal-to-binary conversion,
the number is repeatedly divided by 2 and the remainders obtained using
% 2 form the binary digits.

2
PIYASHA BHATTACHARJEE’S COACHING
Sanskrit | Maths | Science | Computer | English
Online Tutor for Batches and 1:1 focus for academic excellence

E. Answer the following questions.

1.​ What is the difference between ‘/’ and ‘//’ operation?


Ans.⇒ The ‘/’ operator is used for normal division and it gives the result
in decimal form (float value). For example, 7 / 2 gives 3.5. The
‘//’ operator is called floor division. It divides the numbers and
gives only the whole number part (without decimal). For
example, 7 // 2 gives 3.

2.​ What is the use of the ‘*’ operator in string manipulation ?


Ans.⇒ The ‘*’ operator is used to repeat a string multiple times. It
multiplies the string by a number. For example, if we write "Hi"
* 3, the output will be HiHiHi. It is useful when we want to
print a word or pattern many times.

3.​ Define operators. What is an assignment operator used for ?


Ans.⇒ Operators are special symbols used to perform operations on
variables and values, such as addition, subtraction, or
comparison. An assignment operator is used to assign a value
to a variable. The most common assignment operator is ‘=’. For
example, x = 5 means the value 5 is stored in the variable x.

4.​ Distinguish between logical and relational operators.


Ans.⇒ Relational operators are used to compare two values. They
check conditions like greater than (>), less than (<), or equal to
(==). Logical operators are used to combine two or more
conditions. The main logical operators are AND, OR, and NOT.
Relational operators compare values, while logical operators
combine conditions.

5.​ Differentiate between unary and binary operators.


Ans.⇒Unary operators work on only one value or operand. For
example, the minus sign (-x) changes the sign of a number.
Binary operators work on two values or operands. For example,
+, -, *, and / are binary operators because they need two
numbers to perform the operation.

3
PIYASHA BHATTACHARJEE’S COACHING
Sanskrit | Maths | Science | Computer | English
Online Tutor for Batches and 1:1 focus for academic excellence

6.​ Describe the use of conditional statements. Name its different


forms.
Ans.⇒Conditional statements are used to make decisions in a
program. They help the computer choose what to do based on
a condition. If the condition is true, one action is performed; if it
is false, another action may be performed. The different forms
of conditional statements are: if statement, if-else statement,
and if-elif-else statement.

7.​ Write the syntax of if-else statement.


Ans.⇒student_name = "Manomaya"
if student_name == "Manomaya":
print("Manomaya has submitted the homework to Piyasha
Ma'am.")
else:
print("Homework not submitted to Piyasha Ma'am.")

Common questions

Powered by AI

The '/' operator in Python is used for normal division, providing a decimal result, also known as a float value. For example, 7 / 2 results in 3.5. In contrast, the '//' operator is used for floor division, yielding only the whole number part of the division result. For instance, 7 // 2 provides 3 . The '/' operator is best used when precise decimal values are needed, whereas '//' is preferred when only the integer part is required, such as in calculating indices or iterating in loops where floats are inappropriate.

Floor division (//) and normal division (/) differ in result types and precision of output. Normal division returns a float, capturing precise results with fractional parts. In contrast, floor division returns an integer by discarding remainder values, ensuring whole numbers only . This affects data type management as float results are unsuitable for indexing or situations requiring whole numbers. Choosing between them depends on whether the scenario mandates accuracy and control over fractions or simplified integer results for integral logic or memory optimization.

Conditional statements in Python, such as 'if-elif-else', are central in executing selective logic, permitting code execution based on truth evaluations of expressions. This is especially useful in complex decision trees, where multiple conditions may dictate different outcomes. The 'if-elif-else' structure supports multi-way branching, offering a clear, hierarchical framework to handle various conditions distinctly . This ability means code can be both efficient and adaptable, essential in managing complex scenarios and ensuring comprehensive handling of all possible states in decision-driven applications.

Relational operators in Python compare two values, determining relationships such as greater than or equal to (e.g., '>', '=='). They evaluate conditions to form boolean expressions . Logical operators (AND, OR, NOT) combine these boolean expressions to manage flow control based on multiple conditions. Understanding the distinction is crucial as relational operators form individual conditions, while logical operators determine the flow's aspect based on the complex combination of conditions. The effective use of both types optimizes decision-making processes and logic within programming .

Conditional statements significantly enhance program efficiency by allowing the execution of specific blocks of code only when particular conditions are met, unlike a purely sequential model which executes every line regardless of necessity. This selective execution conserves computational resources and reduces execution time by bypassing unnecessary calculations and operations . Moreover, it introduces flexibility, enabling adaptive responses to different data inputs or environmental conditions, integral in developing dynamic and responsive software systems.

An if-else statement in Python consists of a condition, a block of code executed when the condition is true, and an optional else branch executed when the condition is false. The condition evaluates to a boolean result; if true, the associated block is executed. If false, and if an else branch exists, the else block runs instead . This mechanism allows Python to handle decision-making processes, executing specific code paths based on dynamic data evaluations.

The modulus operator (%) is used to obtain the remainder of a division operation, particularly useful in scenarios like converting decimal numbers to binary. During this conversion, repeatedly dividing a number by 2 and using the modulus operator to get remainders forms the basis of binary digits . The sequence of remainders, read in reverse, equates to the binary representation of the original number. This method is robust in digital computations and applications requiring bit manipulation or checks for divisibility.

Control statements in Python alter the flow of execution within a program. Sequential statements execute code line by line in order, without deviation. Conditional statements, such as 'if', 'if-else', and 'if-elif-else', execute specific blocks of code based on boolean conditions, directing the flow based on outcomes. Iterative statements, also known as looping statements, repeat a block of code multiple times, such as 'for' and 'while' loops . These structures allow developers to create complex and adaptive logic within programs efficiently.

In Python, operator precedence determines the order in which operations are evaluated. Arithmetic operators like '*', '/', and '+' have specific precedence levels, with higher precedence operators being evaluated before lower ones. Logical operators such as 'AND' and 'OR' also follow precedence rules, where 'AND' is evaluated before 'OR'. This hierarchy ensures that expressions are evaluated in a predictable manner, ensuring logical correctness in conditions and calculations . For example, in the expression '3 + 5 * 2', the multiplication is performed first, resulting in 13, due to higher precedence.

Unary operators in Python operate on a single operand, for example, the negation operator '-' which inverts a number's sign, while binary operators require two operands, like the addition operator '+' which combines two numbers. The distinction is significant as it defines the operand number needed and influences expression and logic design. For example, unary operators are pivotal in transformations or checks on single data points, whereas binary operators form relationships between data sets, crucial in arithmetic or comparison operations .

You might also like