Practice programs-Functions
Practice programs-Functions
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.
Expected Output:
8. Write a Python function that takes a list and returns a new list with distinct elements from
the first list.
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.
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: