Unit 2: Control Flow, Functions, and Problem-Solving - Subjective Questions

CSR101 — Python Programming • Practice Questions with Detailed Answers

20 questions

1

Explain the use of conditional statements in Python. Describe the syntax and working of if, if-else, and if-elif-else statements with suitable examples.

2

Compare for loops and while loops in Python. Explain when each type of loop is appropriate and provide an example of both.

3

Explain nested loops in Python. Develop a program using nested loops to print a rectangular pattern of stars and describe how the program works.

4

Distinguish between the break and continue statements in Python. Illustrate both using a suitable loop example.

5

Explain the range() function in Python. Describe its different forms and show how it can be used for counting in ascending and descending order.

6

Design an algorithm and write Python code to count the number of vowels, consonants, digits, and spaces in a given string.

7

Define a function in Python and explain its advantages. Describe parameters, arguments, local variables, and the role of the return statement with examples.

8

Explain positional arguments, keyword arguments, default arguments, and variable-length arguments in Python functions with suitable examples.

9

Explain recursion in Python. Write a recursive function to calculate the factorial of a non-negative integer and identify its base case and recursive case.

10

What is a lambda function in Python? Compare lambda functions with ordinary functions and demonstrate their use with a sorting or mapping operation.

11

Explain string indexing and slicing in Python. Describe positive and negative indices and write expressions to extract substrings, reverse a string, and select characters at intervals.

12

Describe important Python string methods. Explain the purpose of methods such as lower(), upper(), strip(), replace(), find(), startswith(), and endswith() with examples.

13

Explain how strings are split and joined in Python. Write a program that accepts a comma-separated list of names, removes extra spaces, and produces a hyphen-separated string.

14

Explain advanced string formatting in Python using f-strings and the format() method. Include examples involving alignment, decimal precision, and formatted expressions.

15

Differentiate between string concatenation, f-string formatting, and the format() method. Discuss the advantages and limitations of each approach.

16

What are regular expressions? Explain the roles of the re module, character classes, quantifiers, anchors, and the search() and findall() functions with examples.

17

Develop a regular expression-based Python program to validate a simple email address. Explain the pattern and discuss why regular expressions alone may not guarantee that an email address is fully valid.

18

Explain algorithmic thinking and describe how decomposition, pattern recognition, abstraction, and step-by-step algorithm design help solve programming problems.

19

Write and explain a Python program to find the largest, smallest, and average values in a list of numbers without using built-in max(), min(), or sum() functions.

20

Design an algorithm and write a Python function to determine whether a given string is a palindrome. Explain how string slicing and a loop-based approach can both solve the problem.