Practice Programs using Functions
1. Write a Python function to find the maximum of three numbers.
2. Write a Python function to sum all the numbers in a list.
Sample List: (8, 2, 3, 0, 7)
Expected Output: 20
3. Write a Python function to multiply all the numbers in a list.
Sample List: (8, 2, 3, -1, 7)
Expected Output: -336
4. Write a Python program to reverse a string.
Sample String: "1234abcd"
Expected Output: "dcba4321"
5. Write a Python function to calculate the factorial of a number (a non-negative integer). The
function accepts the number as an argument.
6. Write a Python function to check whether a number falls within a given range.
7. Write a Python function that accepts a string and counts the number of upper and lowercase
letters.
Sample String: 'The quick Brow Fox'
Expected Output:
No. of Uppercase characters: 3
No. of Lowercase Characters: 12
8. Write a Python function that takes a list and returns a new list with distinct elements from
the first list.
Sample List: [1,2,3,3,3,3,4,5]
Unique List: [1, 2, 3, 4, 5]
9. Write a Python function that takes a number as a parameter and checks whether the
number is prime or not.
Note: A prime number (or a prime) is a natural number greater than 1 and that has no
positive divisors other than 1 and itself.
10. Write a Python program to print the even numbers from a given list.
Sample List: [1, 2, 3, 4, 5, 6, 7, 8, 9]
Expected Result: [2, 4, 6, 8]
11. Write a Python function that checks whether a passed string is a palindrome or not.
Practice Programs using Functions
12. Note: A palindrome is a word, phrase, or sequence that reads the same backward as
forward, e.g., madam or nurses run.
13. Write a Python function to create and print a list where the values are the squares of
numbers between 1 and 30 (both included).
14. Write a Python program to execute a string containing Python code.
15. Write a Python program to detect the number of local variables declared in a function.
Sample Output: