GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python functions - Exercises, Practice, Solution - w3resource

  • Home
  • Python Home
  • ▼Python Exercises
  • Exercises Home
  • ▼Python Basic
  • Basic - Part-I
  • Basic - Part-II
  • Python Programming Puzzles
  • Mastering Python
  • ▼Python Advanced
  • Python Advanced Exercises
  • ▼Python Control Flow
  • Condition Statements and Loops
  • Recursion
  • ▼Python Data Types
  • String
  • JSON
  • List
  • List Advanced
  • Dictionary
  • Tuple
  • Sets
  • Collections
  • Array
  • Enum
  • ▼Python Class
  • Class
  • ▼Python Concepts
  • Python Unit test
  • Python Exception Handling
  • Python Object-Oriented Programming
  • Decorator
  • ▼Functional Programming
  • Functions
  • Lambda
  • Map
  • Itertools
  • Filter Function
  • ▼Date and Time
  • Date Time
  • Pendulum Module
  • ▼File Handling
  • File I/O
  • CSV Read, Write
  • ▼Regular Expressions
  • Regular Expression
  • ▼Data Structures and Algorithms
  • Search and Sorting
  • Linked List
  • Binary Search Tree
  • Heap queue algorithm
  • Bisect
  • ▼Advanced Python Data Types
  • Boolean Data Type
  • None Data Type
  • Bytes and Byte Arrays
  • Memory Views exercises
  • Frozenset Views exercises
  • NamedTuple exercises
  • OrderedDict exercises
  • Counter exercises
  • Ellipsis exercises
  • ▼Concurrency and Threading
  • Threading
  • Asynchronous
  • ▼Python Modules
  • Modules
  • Operating System Services
  • Math
  • Requests
  • SQLite Database
  • SQLAlchemy
  • PPrint
  • ▼Miscellaneous
  • Cyber Security
  • Generators Yield
  • ▼Python GUI Tkinter, PyQt
  • Tkinter Home
  • Tkinter Basic
  • Tkinter Layout Management
  • Tkinter Widgets
  • Tkinter Dialogs and File Handling
  • Tkinter Canvas and Graphics
  • Tkinter Events and Event Handling
  • Tkinter Custom Widgets and Themes
  • Tkinter File Operations and Integration
  • PyQt Basic
  • PyQt Widgets
  • PyQt Connecting Signals to Slots
  • PyQt Event Handling
  • ▼Python NumPy
  • Python NumPy Home
  • ▼Python urllib3
  • Python urllib3 Home
  • ▼Python Metaprogramming
  • Python Metaprogramming Home
  • ▼Python GeoPy
  • Python GeoPy Home
  • ▼BeautifulSoup
  • BeautifulSoup Home
  • ▼Arrow Module
  • Arrow Home
  • ▼Python Pandas
  • Python Pandas Home
  • ▼Pandas and NumPy Exercises
  • Pandas and NumPy Home
  • ▼Python Machine Learning
  • Machine Learning Home
  • TensorFlow Basic
  • ▼Python Web Scraping
  • Web Scraping
  • ▼Python Challenges
  • Challenges-1
  • ▼Python Mini Project
  • Python Projects
  • ▼Python Natural Language Toolkit
  • Python NLTK
  • ▼Python Project
  • Novel Coronavirus (COVID-19)
  • ..More to come..

Python functions - Exercises, Practice, Solution

Last update on July 12 2025 13:12:38 (UTC/GMT +8 hours)


This resource offers a total of 105 Python functions problems for practice. It includes 21 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

[An Editor is available at the bottom of the page to write and execute the scripts.]


1. Maximum of Three Numbers

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

Click me to see the sample solution


2. Sum All Numbers in a List

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

Sample List : (8, 2, 3, 0, 7)
Expected Output : 20
Click me to see the sample solution


3. Multiply All Numbers in a List

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

Sample List : (8, 2, 3, -1, 7)
Expected Output : -336
Click me to see the sample solution


4. Reverse a String

Write a Python program to reverse a string.

Sample String : "1234abcd"
Expected Output : "dcba4321"
Click me to see the sample solution


5. Factorial of a Number

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

Click me to see the sample solution


6. Check if a Number Falls Within a Given Range

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

Click me to see the sample solution


7. Count Uppercase and Lowercase Letters in a String

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
Click me to see the sample solution


8. Return a New List with Distinct Elements from a List

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]
Click me to see the sample solution


9. Check Whether a Number is Prime

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.
Click me to see the sample solution


10. Print Even Numbers from a Given List

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]
Click me to see the sample solution


11. Check if a Number is Perfect

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.
Click me to see the sample solution


12. Check if a String is a Palindrome

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.
Click me to see the sample solution


13. Print the First n Rows of Pascal's Triangle

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 :

Pascal's triangle

Each number is the two numbers above it added together
Click me to see the sample solution


14. Check if a String is a Pangram

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"
Click me to see the sample solution


15. Sort Hyphen-Separated Sequence of Words Alphabetically

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
Click me to see the sample solution


16. Create and Print a List of Squares for Numbers 1 to 30

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

Click me to see the sample solution


17. Create a Chain of Function Decorators (Bold, Italic, Underline, etc.)

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

Click me to see the sample solution


18. Execute a String Containing Python Code

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

Click me to see the sample solution


19. Access a Function Inside a Function

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

Click me to see the sample solution


20. Detect the Number of Local Variables Declared in a Function

Write a Python program to detect the number of local variables declared in a function.

Sample Output:
3
Click me to see the sample solution


21. Invoke a Function After a Specified Period of Time

Write a Python program that invokes a function after a specified period of time.

Sample Output:
Square root after specific miliseconds:
4.0
10.0
158.42979517754858
Click me to see the sample solution


Python Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.