0% found this document useful (0 votes)
4 views1 page

Python Functions Exercise Questions

The document provides a series of Python programming tasks, including functions to find the maximum of three numbers, sum and multiply elements in a list, reverse a string, calculate factorials, check for prime numbers, and identify perfect numbers. It also includes tasks for string manipulation, such as checking for palindromes and pangrams, as well as generating Pascal's triangle and sorting hyphen-separated words. Overall, it serves as a comprehensive guide for practicing various Python functions and concepts.

Uploaded by

arnab.t26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python Functions Exercise Questions

The document provides a series of Python programming tasks, including functions to find the maximum of three numbers, sum and multiply elements in a list, reverse a string, calculate factorials, check for prime numbers, and identify perfect numbers. It also includes tasks for string manipulation, such as checking for palindromes and pangrams, as well as generating Pascal's triangle and sorting hyphen-separated words. Overall, it serves as a comprehensive guide for practicing various Python functions and concepts.

Uploaded by

arnab.t26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Write a Python function to find the maximum of three numbers.

Write a Python function to sum all the numbers in a list.


Sample List : (8, 2, 3, 0, 7)
Expected Output : 20

Write a Python function to multiply all the numbers in a list.


Sample List : (8, 2, 3, -1, 7)
Expected Output : -336

Write a Python program to reverse a string.


Sample String : "1234abcd"
Expected Output : "dcba4321"

Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument.

Write a Python function to check whether a number falls within a given range.

Write a Python function that accepts a string and counts the number of upper and lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12

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]

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.

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]

Write a Python function to check whether a number is "Perfect" or not.


According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also
known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6.
The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.

Write a Python function that checks whether a passed string is a palindrome or not.
Note: A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.

Write a Python function that prints out the first n rows of Pascal's triangle.
Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.
Sample Pascal's triangle :

Each number is the two numbers above it added together

Write a Python function to check whether a string is a pangram or not.


Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"

Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated sequence after sorting them alphabetically.
Sample Items : green-red-yellow-black-white
Expected Result : black-green-red-white-yellow

Write a Python function to create and print a list where the values are the squares of numbers between 1 and 30 (both included).

Write a Python program to create a chain of function decorators (bold, italic, underline etc.).

Write a Python program to execute a string containing Python code.

Write a Python program to access a function inside a function.

Write a Python program to detect the number of local variables declared in a function.
Sample Output:
3

You might also like