Python Function Practice Questions (50)
Level 1: Basics (Q1-Q20)
1. Write a function to return the square of a number.
2. Write a function greet() that prints "Hello, World!".
3. Write a function that returns the sum of two numbers.
4. Write a function that calculates the average of two numbers.
5. Write a function that checks whether a number is even.
6. Write a function that checks whether a number is odd.
7. Write a function that returns the length of a given string.
8. Write a function to calculate the area of a rectangle.
9. Write a function to convert Celsius to Fahrenheit.
10. Write a function to calculate the cube of a number.
11. Write a function to find the greater of two numbers.
12. Write a function to return the first character of a string.
13. Write a function to return the last element of a list.
14. Write a function to return the largest number in a list.
15. Write a function to reverse a string.
16. Write a function that takes a name and returns 'Hello, <name>!'.
17. Write a function to calculate the area of a circle (use pi = 3.14).
18. Write a function to count the vowels in a string.
19. Write a function to check if a number is divisible by 5.
20. Write a function to return the sum of all elements in a list.
Level 2: Intermediate (Q21-Q40)
21. Write a function that returns all even numbers in a list.
22. Write a function that returns all odd numbers in a list.
23. Write a function to return only positive numbers from a list.
24. Write a function to check whether a string is a palindrome.
25. Write a function that counts how many times a word appears in a list.
26. Write a function to remove duplicates from a list.
27. Write a function to find the factorial of a number.
28. Write a function that returns True if a number is prime.
Python Function Practice Questions (50)
29. Write a function that returns a dictionary with words and their lengths.
30. Write a function to sum only the even numbers from a list.
31. Write a function that returns the common elements in two lists.
32. Write a function that checks whether two strings are anagrams.
33. Write a function that accepts a list of numbers and returns the median.
34. Write a function to return the maximum of three numbers.
35. Write a function that returns a list of all divisors of a number.
36. Write a function that returns the count of uppercase letters in a string.
37. Write a function that counts the number of words in a sentence.
38. Write a function that converts a list into a comma-separated string.
39. Write a function to calculate the simple interest (P, R, T).
40. Write a function that checks if a character is a vowel.
Level 3: Advanced / Functional (Q41-Q50)
41. Use map() and a lambda to square all numbers in a list.
42. Use filter() and a lambda to get only even numbers from a list.
43. Write a function using *args that returns the product of all inputs.
44. Write a function using **kwargs to print key-value pairs.
45. Write a function to return a list of tuples (number, square).
46. Use zip() to pair names with scores in a dictionary.
47. Write a function that returns a dictionary of even numbers and their cubes.
48. Write a recursive function to compute the nth Fibonacci number.
49. Write a function that takes a DataFrame column and returns the mean (pandas).
50. Write a function that plots a list using matplotlib.