A collection of educational algorithms in Python for practicing basic programming concepts.
- Python 3.6 or higher
git clone <repository-url>
cd train_algoritm
python3 -m venv venv
On macOS/Linux:
source venv/bin/activate
On Windows:
venv\Scripts\activate
After activation, you'll see (venv)
at the beginning of your terminal prompt.
pip install -r requirements.txt
python train_algorithm.py
When you're done working:
deactivate
-
Even or Odd
- Input a number and determine if it's even or odd.
- Example:
- Input:
7
- Output:
Odd
- Input:
-
Sum of Numbers from 1 to n
- Calculate the sum from 1 up to the given number
n
. - Example:
- Input:
10
- Output:
55
- Input:
- Calculate the sum from 1 up to the given number
-
Factorial
- Calculate the factorial of a given number.
- Example:
- Input:
5
- Output:
120
- Input:
-
Reverse String
- Input a string and get its reverse.
- Example:
- Input:
hello
- Output:
olleh
- Input:
-
Palindrome Check
- Check if the input string is a palindrome (ignores spaces and case).
- Example:
- Input:
Race car
- Output:
Palindrome
- Input:
-
Average of Numbers in a List
- Calculate the arithmetic mean (average) of a list of numbers entered separated by commas or spaces.
- Example:
- Input:
1, 2, 3, 4, 5
- Output:
3.0
- Input:
-
Find Maximum Number in a List
- Find the largest number in a list of numbers entered separated by commas or spaces.
- Example:
- Input:
1, 7, 3, 4, 5
- Output:
7
- Input:
-
Count Occurrences of a Number in a List
- Count how many times a specific number appears in a list of numbers entered separated by commas or spaces.
- Example:
- Input numbers:
1, 2, 3, 2, 4, 2
- Input number to count:
2
- Output:
3
- Input numbers:
-
Get Even Numbers from a List
- Return all even numbers from a list entered separated by commas or spaces.
- Example:
- Input:
1, 2, 3, 4, 5, 6
- Output:
2, 4, 6
- Input:
-
Get Unique Numbers from a List
- Return all unique numbers from a list entered separated by commas or spaces, preserving their order.
- Example:
- Input:
1, 2, 2, 3, 4, 3, 5
- Output:
1, 2, 3, 4, 5
- Input:
-
NBU Currency Exchange Rates
- Fetch current exchange rates from the National Bank of Ukraine API for USD and EUR.
- No input required - automatically displays current rates.
- Example output:
┌─────────────────────────┐ │ 💰 Currency: USD │ │ 💵 Exchange: 41.2215 │ │ 📅 Date: 02.10.2025 │ └─────────────────────────┘
-
🎯 Two Sum (LeetCode #1)
- Classic LeetCode problem for algorithm practice.
- Given an array of integers and a target sum, find the indices of two numbers that add up to the target.
- Uses nested loops approach (Brute Force) with O(n²) time complexity.
- Great for learning array manipulation and enumerate() function.
- Example:
- Input numbers:
2, 7, 11, 15
- Input target:
9
- Output:
0 1
(because nums[0] + nums[1] = 2 + 7 = 9)
- Input numbers:
Run the script and choose an algorithm by name or number:
python train_algorithm.py
When prompted, enter one of the following:
one
or1
for Even or Oddtwo
or2
for Sum of Numbersthree
or3
for Factorialfour
or4
for Reverse Stringfive
or5
for Palindrome Checksix
or6
for Average of Numbers in a Listseven
or7
for Find Maximum Number in a Listeight
or8
for Count Occurrences of a Number in a Listnine
or9
for Get Even Numbers from a Listten
or10
for Get Unique Numbers from a Listeleven
or11
for NBU Currency Exchange Ratestwelve
or12
for Two Sum (LeetCode #1)
$ python train_algorithm.py
Write algorithm number(one, two, three ... etc): five
Write string: Race car
Palindrome
$ python train_algorithm.py
Write algorithm number(one, two, three ... etc): 11
┌─────────────────────────┐
│ 💰 Currency: USD │
│ 💵 Exchange: 41.2215 │
│ 📅 Date: 02.10.2025 │
└─────────────────────────┘
┌─────────────────────────┐
│ 💰 Currency: EUR │
│ 💵 Exchange: 48.3734 │
│ 📅 Date: 02.10.2025 │
└─────────────────────────┘
train_algoritm/
├── README.md # Project documentation
├── train_algorithm.py # Main program with all algorithms
├── requirements.txt # Python dependencies
└── venv/ # Virtual environment (created by you)
- Most algorithms use only Python's standard library (
re
module for regex) - Algorithm #11 requires the
requests
library for API calls to NBU - External packages are listed in
requirements.txt
- Virtual environment is recommended but optional
- All algorithms include basic error handling for invalid inputs
This is an educational project for learning purposes.