Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
677a625
Delete starter/problem1.txt
Muntasir-Rahman-Saikat Sep 27, 2025
459949f
Delete starter/Solution1.py
Muntasir-Rahman-Saikat Sep 27, 2025
033e75e
problem-1 update
Muntasir-Rahman-Saikat Sep 27, 2025
11bc26d
Problem1 updated
Muntasir-Rahman-Saikat Sep 27, 2025
f91e582
Problem2 updated
Muntasir-Rahman-Saikat Sep 27, 2025
7785c90
Merge branch 'main' of github.com:Muntasir-Rahman-Saikat/python-pract…
Muntasir-Rahman-Saikat Sep 27, 2025
ef4d583
Problem3 updated
Muntasir-Rahman-Saikat Sep 27, 2025
afd5e69
Problem4 updated
Muntasir-Rahman-Saikat Sep 27, 2025
92aafe0
problem4 updated
Muntasir-Rahman-Saikat Sep 27, 2025
8e7e711
problem-5 updated
Muntasir-Rahman-Saikat Sep 27, 2025
022ce45
problem-6 updated
Muntasir-Rahman-Saikat Sep 27, 2025
4981d9c
prblem-7 updated
Muntasir-Rahman-Saikat Sep 27, 2025
dc26b79
problem-8 updated
Muntasir-Rahman-Saikat Sep 27, 2025
39927b1
problem9 updated
Muntasir-Rahman-Saikat Sep 27, 2025
d185c8f
problem-10 updated
Muntasir-Rahman-Saikat Sep 27, 2025
9f5de04
renamed folder 10
Muntasir-Rahman-Saikat Sep 27, 2025
167963f
All files renamed
Muntasir-Rahman-Saikat Sep 27, 2025
c615698
Problem-11 updated
Muntasir-Rahman-Saikat Sep 28, 2025
32ff16a
problem 12 and 13 updated
Muntasir-Rahman-Saikat Sep 28, 2025
fa80401
problem14 and 15 updated
Muntasir-Rahman-Saikat Sep 29, 2025
1a658cd
beginner level updated
Muntasir-Rahman-Saikat Sep 30, 2025
6953027
updated
Muntasir-Rahman-Saikat Sep 30, 2025
d312d75
Intermedite levels code updated
Muntasir-Rahman-Saikat Oct 10, 2025
915c2d6
Advanced level updated
Muntasir-Rahman-Saikat Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
5 changes: 5 additions & 0 deletions advanced-level/problem-1/log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INFO: Application started
ERROR: Failed to connect to the database
INFO: Processing request ID 123
ERROR: Timeout while waiting for response
INFO: Shutdown complete
3 changes: 3 additions & 0 deletions advanced-level/problem-1/problem-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Problem-1: Docker Log Analyzer
Build a script that reads a Docker log file and returns error messages with timestamps.
Hint: Look for keywords like "ERROR" or "Exception" using regex.
13 changes: 13 additions & 0 deletions advanced-level/problem-1/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Make logger.py executable
chmod 700 solution-1.py

# Make script.sh executable
chmod 700 solution.sh

echo "Permissions set to 700 for logger.py and script.sh."

echo "Running ./script.sh file to check Error logs"

./solution.sh
17 changes: 17 additions & 0 deletions advanced-level/problem-1/solution-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def check_for_log_errors(log_file_path):
try:
with open(log_file_path,'r') as file:

lines=file.readlines()
errors=[error for error in lines if 'ERROR' in error]
if errors:
print('Error found in the log file')
for error in errors:
print(error.strip())
else:
print('No error found')
except FileNotFoundError:
print(f"Log file {log_file_path} not found.")
if __name__=="__main__":
log_file_path="log"
check_for_log_errors(log_file_path)
13 changes: 13 additions & 0 deletions advanced-level/problem-1/solution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
PYTHON_SCRIPT='solution-1.py'
INTERVAL=10

echo "staring the log checker.Press Ctrl+C for termination"

while true
do
echo "running the python script to check for errors"
python3 "$PYTHON_SCRIPT"
echo "Explicitely sleeping for interval seconds"
sleep $INTERVAL
done
2 changes: 2 additions & 0 deletions advanced-level/problem-10/problem-10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implement a simple .env file loader for config in DevOps.
Hint: Use dotenv library or parse lines manually and set in os.environ.
10 changes: 10 additions & 0 deletions advanced-level/problem-10/solution-10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dotenv import load_dotenv
import os

# Load variables from .env into environment
load_dotenv(dotenv_path="solution.env")

# Access them
print("DB User:", os.getenv("DB_USER"))
print("DB Password:", os.getenv("DB_PASS"))
print("Debug Mode:", os.getenv("DEBUG"))
3 changes: 3 additions & 0 deletions advanced-level/problem-10/solution.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_USER=admin
DB_PASS=secret123
DEBUG=True
2 changes: 2 additions & 0 deletions advanced-level/problem-2/problem-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Scrape a sample blog page and return all titles within <h2> tags.
Hint: Use BeautifulSoup and requests.
25 changes: 25 additions & 0 deletions advanced-level/problem-2/solution-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import requests
from bs4 import BeautifulSoup

def get_h2_titles(url):
# send HTTP GET request
resp = requests.get(url)
resp.raise_for_status() # raise error for bad status codes

# parse HTML
soup = BeautifulSoup(resp.text, "html.parser")

# find all <h2> tags
h2_tags = soup.find_all("h2")
print(h2_tags)

# extract their text
titles = [h2.get_text(strip=True) for h2 in h2_tags]
return titles

if __name__ == "__main__":
url = "https://medium.com/@noureldin_z3r0/how-to-write-the-perfect-blog-post-my-10-000-word-journey-7b5b38525848"
titles = get_h2_titles(url)
print("H2 titles found:")
for idx, t in enumerate(titles, 1):
print(f"{idx}. {t}")
3 changes: 3 additions & 0 deletions advanced-level/problem-3/problem-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Validate a dynamic JSON input against a predefined schema before database insertion.
Hint: Use jsonschema library or manually check key types.

26 changes: 26 additions & 0 deletions advanced-level/problem-3/solution-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from jsonschema import validate, ValidationError

# Define the schema
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"email": {"type": "string", "format": "email"}
},
"required": ["name", "age", "email"]
}

# Example JSON input
data = {
"name": "Muntasir Rahman Saikat",
"age": 22,
"email": "[email protected]"
}

# Validate the data
try:
validate(instance=data, schema=schema)
print(" JSON is valid! Proceed to insert into database.")
except ValidationError as e:
print("❌ JSON validation failed:", e.message)
3 changes: 3 additions & 0 deletions advanced-level/problem-4/problem-4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Create a Mini REST API with Flask
Build a mini Flask app with /tasks endpoint to GET, POST, and DELETE tasks from a list.
Hint: Use Flask's route decorators.
31 changes: 31 additions & 0 deletions advanced-level/problem-4/solution-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from flask import Flask, request, jsonify

app = Flask(__name__)

# In-memory list of tasks
tasks = [
{"id": 1, "title": "Learn Python"},
{"id": 2, "title": "Build a REST API"}
]

# GET: Retrieve all tasks
@app.route('/tasks', methods=['GET'])
def get_tasks():
return jsonify(tasks)

# POST: Add a new task
@app.route('/tasks', methods=['POST'])
def add_task():
new_task = request.get_json()
tasks.append(new_task)
return jsonify({"message": "Task added successfully!"}), 201

# DELETE: Remove a task by ID
@app.route('/tasks/<int:task_id>', methods=['DELETE'])
def delete_task(task_id):
global tasks
tasks = [t for t in tasks if t['id'] != task_id]
return jsonify({"message": f"Task {task_id} deleted!"})

if __name__ == '__main__':
app.run(debug=True)
3 changes: 3 additions & 0 deletions advanced-level/problem-5/problem-5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Problem-5: Calculate Pearson Correlation
Given two lists, calculate the correlation coefficient (e.g., feature correlation in ML).
Hint: Use formula or scipy.stats.pearsonr().
7 changes: 7 additions & 0 deletions advanced-level/problem-5/solution-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from scipy.stats import pearsonr

X = [10, 20, 30, 40, 50]
Y = [10, 27, 35, 45, 55]

corr,p_value= pearsonr(X, Y)
print("Pearson correlation coefficient:", corr,p_value)
Binary file added advanced-level/problem-6/mydata.xlsx
Binary file not shown.
3 changes: 3 additions & 0 deletions advanced-level/problem-6/problem-6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Problem-6: Read CSV and Return Top Records
Read a CSV of users and return top 5 users by score.
Hint: Use csv.DictReader or pandas.
15 changes: 15 additions & 0 deletions advanced-level/problem-6/solution-6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from operator import index

import pandas as pd

# Step 1: Read the CSV file
data = pd.read_excel(r'/home/wsl-ubuntu/Python_task/python-practice-problems/advanced-level/problem-6/mydata.xlsx')

# Step 2: Sort by 'score' in descending order (highest first)
sorted_data = data.sort_values(by='marks', ascending=False)

# Step 3: Get top 5 records
top_5 = sorted_data.head(5)

# Step 4: Display result
print(top_5)
Empty file.
Empty file.
Empty file added advanced-level/problem-7/h.txt
Empty file.
3 changes: 3 additions & 0 deletions advanced-level/problem-7/problem-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Problem-7: Simulate File Watcher in a Directory
Monitor a folder and detect when new .txt files are added.
Hint: Use os.listdir() in a loop or watchdog.
Empty file added advanced-level/problem-7/sa.txt
Empty file.
23 changes: 23 additions & 0 deletions advanced-level/problem-7/solution-7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import time

def watch_directory(path):
print(f"Watching directory: {path}")
existing_files = set(os.listdir(path))

while True:
time.sleep(8) # check every 8 seconds
current_files = set(os.listdir(path))

# detect new .txt files
new_files = [f for f in current_files - existing_files if f.endswith('.txt')]

if new_files:
for file in new_files:
print(f"New text file detected: {file}")

existing_files = current_files

# Example usage
directory_path = "/home/wsl-ubuntu/Python_task/python-practice-problems/advanced-level/problem-7" # change path as needed
watch_directory(directory_path)
2 changes: 2 additions & 0 deletions advanced-level/problem-8/problem-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Multiply two matrices, often needed in neural net computations.
Hint: Use nested loops or numpy.dot().
10 changes: 10 additions & 0 deletions advanced-level/problem-8/solution-8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import numpy as np

A = np.array([[1, 2, 3],
[4, 5, 6]])

B = np.array([[7, 8],
[9, 10],
[11, 12]])
result=np.dot(A,B)
print(result)
Binary file added advanced-level/problem-9/IMG_20221102_170856.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added advanced-level/problem-9/grayscale_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions advanced-level/problem-9/problem-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Write a function to convert a color image to grayscale and save it.
Hint: Use Pillow (PIL.Image.open().convert("L")).
22 changes: 22 additions & 0 deletions advanced-level/problem-9/solution-9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from PIL import Image


def convert_to_grayscale(input_path, output_path):
"""
Converts a color image to grayscale and saves it.
Args:
input_path (str): Path to the input color image.
output_path (str): Path to save the grayscale image.
"""
# Open the color image
image = Image.open(input_path)

# Convert to grayscale ('L' mode = 8-bit pixels, black and white)
gray_image = image.convert("L")

# Save the grayscale image
gray_image.save(output_path)
print(f"Grayscale image saved as {output_path}")

# Example usage
convert_to_grayscale(r"/home/wsl-ubuntu/Python_task/python-practice-problems/advanced-level/problem-9/IMG_20221102_170856.jpg", r"/home/wsl-ubuntu/Python_task/python-practice-problems/advanced-level/problem-9/grayscale_image.jpg")
10 changes: 10 additions & 0 deletions beginner-level/problem-1/problem-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Reverse a String Without Slicing

You are building a simple text utility tool for your web app. One of the requirements is to reverse a string input by a user.

Input: "bongodev"

Output: "vedognob"

Hint: Use a loop to read the string from end to start.

8 changes: 8 additions & 0 deletions beginner-level/problem-1/solution-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Input="bongodev"

def reverese_string(s):
x = ""
for i in range(len(s)-1,-1,-1):
x+=s[i]
print(x)
reverese_string(Input)
5 changes: 5 additions & 0 deletions beginner-level/problem-10/problem-10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Check if a Number is Prime
Write a function to check if a number is prime, useful in some encryption schemes.
Input: 29
Output: True
Hint: Check divisibility from 2 to sqrt(n).
13 changes: 13 additions & 0 deletions beginner-level/problem-10/solution-10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def isprime(m):
import math
for i in range(2,math.floor(m**.5)+1):
print(i)
if m%i!=0:
pass
else:
return "Not a prime number"
return "prime number"
print(isprime(29))

print(isprime(100))

5 changes: 5 additions & 0 deletions beginner-level/problem-2/problem-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Count Vowels in a Sentence
As part of a data-cleaning pipeline, count how many vowels are in a string to later analyze readability.
Input: "Data Science is awesome"
Output: 9
Hint: Convert string to lowercase and check each character.
10 changes: 10 additions & 0 deletions beginner-level/problem-2/solution-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Input="Data Science is Awesome"

def vowel_numbers(s):
vowels = ["a", "e", "i", "o", "u"]
count=0
for i in s.lower():
if i in vowels:
count+=1
print(count)
vowel_numbers(Input)
5 changes: 5 additions & 0 deletions beginner-level/problem-3/problem-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Find Duplicates in a List
You’re given a user-uploaded list of tags. Identify duplicates for suggestion cleanup.
Input: ["ai", "ml", "python", "ml", "dl", "ai"]
Output: ["ml", "ai"]
Hint: Use a dictionary or set to track seen elements
12 changes: 12 additions & 0 deletions beginner-level/problem-3/solution-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Input= ["ai", "ml", "python", "ml", "dl", "ai"]
def duplicates(s):
x=[]
duplicate=[]
for i in s:
if i in x:
duplicate.append(i)
else:
x.append(i)
print(duplicate)
duplicates(Input)

7 changes: 7 additions & 0 deletions beginner-level/problem-4/problem-4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Write a function that checks if a word or phrase is the same when reversed, ignoring spaces and punctuation.

Input: "Madam"

Output: True

Hint: Normalize the string and compare it to its reverse.
20 changes: 20 additions & 0 deletions beginner-level/problem-4/solution-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
input_text = "Madam"
input_text2 = "A sman, a plan, a canal, Panama"
def palindrome(x):
p=x.replace(" ", "").replace(",", "").lower()
left=0
right= len(p) - 1
same_char=True
while left<right:
if p[left]!=p[right]:
same_char=False
break
else:
left+=1
right-=1
if same_char:
print("True")
else:
print("False")
palindrome(input_text2)

5 changes: 5 additions & 0 deletions beginner-level/problem-5/problem-5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flatten a Nested List
You are given a nested list of elements (e.g., UI config data). Flatten it into a single-level list.
- **Input**: `[1, [2, 3], [4, [5]]]`
- **Output**: `[1, 2, 3, 4, 5]`
- **Hint**: Use recursion to handle sublists.
13 changes: 13 additions & 0 deletions beginner-level/problem-5/solution-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Input =[1, [2, 3], [4, [5],(5,2)]]
def flattens(x):
result=[]
for values in x:
if isinstance(values,(list,tuple)):
result.extend(flattens(values))
else:
result.append(values)
return result
print(flattens(Input))



Loading