Fundamentals 5 min read

Python Programming Exercises: Sorting, Math, File Operations, and More

This article presents a comprehensive collection of over thirty Python programming exercises covering basic algorithms such as bubble sort, mathematical computations, string manipulation, file system operations, and utility scripts, each illustrated with code screenshots to help learners practice and master fundamental coding skills.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Exercises: Sorting, Math, File Operations, and More

1. Bubble Sort

2. Compute x to the power of n

3. Compute a*a + b*b + c*c + …

4. Compute factorial n!

5. List all files and directories in the current directory

6. Convert all strings in a list to lowercase

7. Output all file and folder paths under a given directory

8. Output all file paths under a given path and its subdirectories

9. Output all .html files under a given path and its subdirectories

10. Invert a dictionary's key‑value pairs to create a new dictionary

11. Print the multiplication table (九九乘法表)

12. Replace all occurrences of 3 with "3a" in a list

13. Print each name in a list

14. Merge lists and remove duplicates

15. Two methods to generate random verification codes

16. Compute square root

17. Check if a string consists only of digits

18. Determine odd or even numbers

19. Determine leap years

20. Find the maximum value in a list

21. Fibonacci sequence explanation

Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13 … where each term from the third onward equals the sum of the two preceding terms.

22. Convert decimal to binary, octal, and hexadecimal

23. Compute greatest common divisor (GCD)

24. Compute least common multiple (LCM)

25. Simple calculator

26. Generate a calendar

27. File I/O operations

28. String type checking

29. Convert string case (upper/lower)

30. Calculate the number of days in each month

31. Get yesterday's date

PythonProgrammingAlgorithmscode examplesBasicsexercises
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.