Python Function Assignments
Section A: Basics of Functions
1. Create a function greet() that prints "Hello, Welcome to Python!"
2. Create a function add() that takes two numbers and returns their sum.
3. Create a function is_even(num) that returns True if the number is even, else False.
4. Write a function to calculate the square of a number.
5. Create a function that prints all even numbers from 1 to N.
Section B: Parameters and Return Values
6. Write a function multiply(a, b) that returns the product of two numbers.
7. Create a function power(base, exponent) to calculate base^exponent.
8. Define a function is_prime(n) to check if a number is prime.
9. Write a function that accepts marks and returns grade:
o 90+ → A
o 80-89 → B
o 70-79 → C
o else → D
10. Create a function that accepts a name and age, and returns a formatted string:
"Hi [Name], you are [Age] years old."
Section C: String and List Functions
11. Write a function to count vowels in a string.
12. Write a function reverse_string(s) to return the reversed string.
13. Write a function that accepts a list and returns only odd numbers from it.
14. Write a function that returns the largest element in a list.
15. Write a function that takes a string and returns its word count.
Section D: Special Features
16. Write a function using *args to calculate the sum of all arguments.
17. Write a function using **kwargs to print all key-value pairs.
18. Create a lambda function to multiply two numbers.
19. Use map() to convert all words in a list to uppercase.
20. Use filter() to extract all numbers greater than 50 from a list.
21. Use reduce() to find the product of all elements in a list.
Section E: Mini Projects (Functions-Based)
Section A: Basics of Functions
1. Create a function greet() that prints "Hello, Welcome to Python!"
2. Create a function add() that takes two numbers and returns their sum.
3. Create a function is_even(num) that returns True if the number is even, else False.
4. Write a function to calculate the square of a number.
5. Create a function that prints all even numbers from 1 to N.
Section B: Parameters and Return Values
6. Write a function multiply(a, b) that returns the product of two numbers.
7. Create a function power(base, exponent) to calculate base^exponent.
8. Define a function is_prime(n) to check if a number is prime.
9. Write a function that accepts marks and returns grade:
o 90+ → A
o 80-89 → B
o 70-79 → C
o else → D
10. Create a function that accepts a name and age, and returns a formatted string:
"Hi [Name], you are [Age] years old."
Section C: String and List Functions
11. Write a function to count vowels in a string.
12. Write a function reverse_string(s) to return the reversed string.
13. Write a function that accepts a list and returns only odd numbers from it.
14. Write a function that returns the largest element in a list.
15. Write a function that takes a string and returns its word count.
Section D: Special Features
16. Write a function using *args to calculate the sum of all arguments.
17. Write a function using **kwargs to print all key-value pairs.
18. Create a lambda function to multiply two numbers.
19. Use map() to convert all words in a list to uppercase.
20. Use filter() to extract all numbers greater than 50 from a list.
21. Use reduce() to find the product of all elements in a list.
Section E: Mini Projects (Functions-Based)