Unit 2: Conditionals and Iterations; Functions and Recursion - Subjective Questions

ECE181 — Introduction To Python • Practice Questions with Detailed Answers

20 questions

1

Define a conditional expression in Python. Explain how the ternary conditional operator works with a suitable example.

2

Explain the if statement in Python. Describe its syntax and illustrate with a flowchart-like explanation and an example.

3

Distinguish between a two-way if-else statement and a multi-way if-elif-else statement with examples.

4

What is a nested if statement? Explain with an example where nested conditions are necessary.

5

Explain the for loop in Python. Describe the use of the range() function with examples.

6

Describe the while loop in Python. How does it differ from the for loop? Provide an example of each.

7

What are nested loops? Write a program to print the following pattern using nested loops and explain its working.

*

  • *
    • *

8

Explain the break and continue statements in Python with suitable examples. How do they alter the flow of loops?

9

Explain how random numbers are generated in Python using the random module. Describe at least four useful functions with examples.

10

What is a function call in Python? Explain the process of calling a function and how values are returned, with an example.

11

Explain type conversion and type coercion in Python. Distinguish between implicit and explicit type conversion with examples.

12

Describe the math module in Python. List and explain at least five commonly used math functions with examples.

13

Explain the steps of adding a new function in Python. What are the advantages of using functions in a program?

14

Distinguish between parameters and arguments in Python functions. Explain different types of arguments with examples.

15

What is recursion? Explain its key components. Write a recursive function to compute the factorial of a number and explain its working.

16

Compare recursion and iteration. Discuss the advantages and disadvantages of recursion, and mention where recursion is preferred.

17

Write a Python program using a while loop to check whether a given number is a prime number. Explain the logic used.

18

Explain the concept of variable scope in the context of functions. Distinguish between local and global variables with examples.

19

Write a Python program to generate the Fibonacci series up to terms using recursion, and explain the recursive relation used.

20

Explain how logical operators (and, or, not) are used in conditional expressions. Illustrate with a program that uses multiple conditions.