
Python: Problems for Basics Reference — Swapping, Factorial, Reverse Digits, Pattern Print
I started learning Python in the last 6 months. But every time I learn any new concept in Python, I invariably refer to some of the basic problems which I’ve done while learning.
I’m just sharing those concepts with you guys, who are in similar situation or for whom, wants to learn basic concepts.
- Swapping:
You are given two integer variables, x and y. You have to swap the values stored in x and y. Without using 3rd variable.
Swapping two integers by using 3rd variable is easy. But without 3rd variable you can directly swap the integers in Python.
By simply writing
x,y = y,x
we can easily swap the integers.

2. Factorial:
A factorial is calculated for integers greater than or equal to zero and is defined as:
n!=1×2×3×4×5…×n

Don’t forget to handle the cases for inputs < 0 and ==0.
3. Reverse Digits:
Given a number, reverse the number.
For example:
number = 12345
output = 54321

4. Pattern Printing:
If anyone wants to master loop iterations, Pattern Printing is the best example.
Following is the pattern which needs to be printed.


Conclusion:
These are some of the Basic concepts, which needs to be mastered before proceeding to high level concepts in Python.
There are some more concepts, which I will share in the coming week.
Thanks for reading and Happy Coding.
