Unit 2: Conditional and Iterative Statements - Subjective Questions

INT108 — Python Programming • Practice Questions with Detailed Answers

20 questions

1

Define the modulus operator in Python. Explain its behavior with suitable examples and mention two practical applications.

2

Explain how random numbers are generated in Python using the random module. Distinguish between random(), randint(), and randrange().

3

What is a Boolean expression? Describe comparison operators and explain how Python evaluates truth values.

4

Explain the logical operators and, or, and not with truth tables and suitable Python examples.

5

Describe the syntax and working of if, if-else, and if-elif-else statements in Python.

6

Compare nested conditional statements with an if-elif-else ladder. Illustrate both forms with examples.

7

Write and explain a Python program that determines whether a given year is a leap year using conditional and logical operators.

8

Define a while statement. Explain initialization, condition testing, updating, and termination with an example.

9

Describe sentinel-controlled iteration and write a while loop that repeatedly accepts numbers until the user enters -1, then displays their sum.

10

Explain the for loop and the range() function in Python. Discuss the roles of the start, stop, and step arguments.

11

Distinguish between for and while loops in Python. State situations in which each loop is preferable.

12

Explain the purpose and behavior of break, continue, and the loop else clause in Python.

13

Write and explain a Python program using nested for loops to print a multiplication table from to .

14

Describe the execution of nested while loops. Write a program that prints a right-angled triangular pattern of five rows.

15

Compare nested for loops and nested while loops with respect to structure, control, readability, and applications.

16

Write a Python program that simulates rolling two dice repeatedly until their sum is . Explain the use of random numbers and loop termination.

17

Explain how random numbers can be used inside a for loop to estimate the probability of an event. Illustrate with a coin-toss simulation.

18

What is encapsulation in program development? Explain how a repeated conditional or iterative task can be encapsulated in a Python function.

19

Define generalization in programming. Show how a specific loop can be generalized using function parameters.

20

Design a generalized and encapsulated number-guessing game in Python. The program should generate a random number, use a loop, provide conditional feedback, and limit the number of attempts.