0% found this document useful (0 votes)
3 views

functions

The document outlines a lesson plan focusing on polymorphism and encapsulation in Java and Data Structures and Algorithms (DSA). It includes a series of theory and practical questions related to Python functions, including definitions, usage, and examples of various concepts such as iterators, generators, and lambda functions. Additionally, it provides practical assignments for implementing functions and programs that demonstrate these concepts.

Uploaded by

JencyShah 2045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

functions

The document outlines a lesson plan focusing on polymorphism and encapsulation in Java and Data Structures and Algorithms (DSA). It includes a series of theory and practical questions related to Python functions, including definitions, usage, and examples of various concepts such as iterators, generators, and lambda functions. Additionally, it provides practical assignments for implementing functions and programs that demonstrate these concepts.

Uploaded by

JencyShah 2045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment

Functions
Lesson Plan

Polymorphism and

Encapsulation

Java + DSA
Theory Questions:

Note: For each theory Question, give at least one example.

1. What is the difference between a function and a method in Python?

2. Explain the concept of function arguments and parameters in Python.

3. What are the different ways to define and call a function in Python?

4. What is the purpose of the `return` statement in a Python function?

5. What are iterators in Python and how do they differ from iterables?

6. Explain the concept of generators in Python and how they are defined.

7. What are the advantages of using generators over regular functions?

8. What is a lambda function in Python and when is it typically used?

9. Explain the purpose and usage of the `map()` function in Python.

10. What is the difference between `map()`, `reduce()`, and `filter()` functions in Python?

11. Using pen & Paper write the internal mechanism for sum operation using reduce function on this given

list:[47,11,42,13];

(Attach paper image for this answer) in doc or colab notebook.


Practical Questions:

1. Write a Python function that takes a list of numbers as input and returns the sum of all even numbers in

the list.

2. Create a Python function that accepts a string and returns the reverse of that string.

3. Implement a Python function that takes a list of integers and returns a new list containing the squares of

each number.

4. Write a Python function that checks if a given number is prime or not from 1 to 200.

5. Create an iterator class in Python that generates the Fibonacci sequence up to a specified number of

terms.

6. Write a generator function in Python that yields the powers of 2 up to a given exponent.

7. Implement a generator function that reads a file line by line and yields each line as a string.

8. Use a lambda function in Python to sort a list of tuples based on the second element of each tuple.

9. Write a Python program that uses `map()` to convert a list of temperatures from Celsius to Fahrenheit.

10. Create a Python program that uses `filter()` to remove all the vowels from a given string.

11) Imagine an accounting routine used in a book shop. It works on a list with sublists, which look like this:

Write a Python program, which returns a list with 2-tuples. Each tuple consists of the order number and the

product of the price per item and the quantity. The product should be increased by 10,- € if the value of the

order is smaller than 100,00 €.

Write a Python program using lambda and map.

You might also like