Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 2 subjective questions Conditionals and Iterations; Functions and Recursion

ECE181 — Introduction To Python 20 questions with model answers. Write yours first, then compare.

Read the notes Practice MCQs
  1. Question 1 of 20

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

  2. Question 2 of 20

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

  3. Question 3 of 20

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

  4. Question 4 of 20

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

  5. Question 5 of 20

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

  6. Question 6 of 20

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

  7. Question 7 of 20

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

    *

    • *
      • *

  8. Question 8 of 20

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

  9. Question 9 of 20

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

  10. Question 10 of 20

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

  11. Question 11 of 20

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

  12. Question 12 of 20

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

  13. Question 13 of 20

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

  14. Question 14 of 20

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

  15. Question 15 of 20

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

  16. Question 16 of 20

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

  17. Question 17 of 20

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

  18. Question 18 of 20

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

  19. Question 19 of 20

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

  20. Question 20 of 20

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

That's unit 2

Long answers stick best when they're tested again soon. Run the MCQs on this unit, then come back to the questions you found hardest.