Thursday, 30 April 2026

April Python Bootcamp Day 18


 

Automation is where Python starts feeling powerful. Instead of manually repeating tasks—like organizing files or setting reminders—you write code once and let it run for you indefinitely.

This session covers two practical domains:

  • File Automation (organizing system files)
  • Task Automation (running scheduled tasks automatically)

Why Automation?

In real-world workflows, repetitive operations consume time and introduce human error. Automation helps to:

  • Eliminate manual effort
  • Improve consistency
  • Save time for high-value work
  • Build real-world applicable skills

Examples:

  • Organizing downloads folder automatically
  • Sending reminders or alerts
  • Running scripts at specific times

File Automation

What is File Automation?

File automation refers to programmatically managing and organizing files based on rules such as file type, size, or naming patterns.

Example:

  • Move .jpg files → Images folder
  • Move .pdf files → Documents folder

Tools Required

  1. os → Interact with file system (list files, create folders)
  2. shutil → Move, copy, delete files

File Organizer Project (Explanation)

Core Logic

  1. Read all files from a directory
  2. Identify file type using extension
  3. Match extension with predefined categories
  4. Move file into corresponding folder
  5. If unmatched → move to "Others"

Code Breakdown

import os
import shutil

# Target folder
source_folder = "C:/Users/91707/Downloads"

# File Type mapping
FILE_TYPES = {
"Images": [".jpg",".png",".jpeg"],
"Documents": [".pdf",".txt",".csv",".docx"],
"Videos": [".mp4",".mkv"]
}

def organize_files():
for file in os.listdir(source_folder):
file_path = os.path.join(source_folder, file)

# Skip folders
if os.path.isdir(file_path):
    continue

_, ext = os.path.splitext(file)

moved = False

for folder, extensions in FILE_TYPES.items():
    if ext.lower() in extensions:
    dest_folder = os.path.join(source_folder, folder)

os.makedirs(dest_folder, exist_ok=True)

shutil.move(file_path, os.path.join(dest_folder, file))
print(f"Moved {file} -> {folder}")
moved = True
break

if not moved:
    others = os.path.join(source_folder, "Others")
    os.makedirs(others, exist_ok=True)
    shutil.move(file_path, os.path.join(others, file))
    print(f"Moved {file} -> Others")

organize_files()

Key Concepts Used

  • os.listdir() → List files in directory
  • os.path.join() → Safe path handling
  • os.makedirs(..., exist_ok=True) → Create folder if not exists
  • os.path.splitext() → Extract extension
  • shutil.move() → Move file

Task Automation

What is Task Automation?

Running a function automatically at a defined interval or specific time.

Examples:

  • Daily study reminder
  • Water intake alert
  • Running scripts at fixed intervals

Tools Required

  1. schedule → Scheduling tasks
  2. time → Delay execution
  3. plyer → Desktop notifications
  4. playsound → Audio alerts

Reminder Automation Project

Core Logic

  1. Create a function (task)
  2. Schedule it using schedule
  3. Run infinite loop to check pending tasks

Code

import schedule
import time
from playsound import playsound
from plyer import notification


def reminder(msg):
    print(f"Reminder: {msg}")

    notification.notify(
        title="Reminder",
        message=msg,
        timeout=5
    )

try:
    playsound("alert.mp3")
except:
    print("Sound file not found")

# Schedule tasks
schedule.every(4).seconds.do(reminder, "Drink Water")
schedule.every().day.at("18:40").do(reminder, "Study Python")

print("Running reminder bot...")

while True:
    schedule.run_pending()
    time.sleep(1)



Important Concepts

1. Function as Task

You pass a function to schedule:

schedule.every(4).seconds.do(reminder, "Drink Water")

2. Infinite Loop

Keeps checking scheduled tasks:

while True:
    schedule.run_pending()
    time.sleep(1)

3. Real-Time Automation

  • Runs continuously
  • Executes tasks at correct timing

Real-World Use Cases

  • Auto file sorter (Downloads, Desktop)
  • Backup system
  • Notification bots
  • Cron-like automation using Python
  • Personal productivity tools

Assignment Questions

Beginner Level

  1. Modify the file organizer to handle .zip and .rar files and move them into an "Archives" folder.
  2. Change the source folder dynamically using user input instead of hardcoding it.
  3. Print total number of files moved after execution.

Intermediate Level

  1. Add a condition:
    Skip files larger than 50MB.
  2. Instead of moving files, copy them using shutil.copy().
  3. Create a log file (log.txt) and store all moved file names.

Advanced Level

  1. Schedule the file organizer to run automatically every day at a specific time.
  2. Add notification after file organization completes:
    • Show number of files organized
  3. Extend the reminder system:
    • Add multiple reminders from a list
    • Example:
      • "Drink Water"
      • "Take Break"
      • "Revise DSA"

Challenge Task

  1. Build a combined automation system:
  • File organizer runs daily at 10 PM
  • Reminder system runs every hour
  • Show desktop notification when both tasks execute

🚀 Day 35/150 – Count Digits in a Number in Python

 

🚀 Day 35/150 – Count Digits in a Number in Python

Counting digits means finding how many digits are present in a number.

Examples:
12345 → 5 digits
900 → 3 digits
0 → 1 digit

Let’s explore different ways to count digits in Python 👇

🔹 Method 1 – Using while Loop

count = 0 while n > 0: n //= 10 count += 1  

print("Digits:", count)



 digit at a time using integer division.

🔹 Method 2 – Taking User Input




n = int(input("Enter a number: ")) count = 0 temp = abs(n) while temp > 0: temp //= 10 count += 1 print("Digits:", count)










✅ Works with negative numbers too.

🔹 Method 3 – Using String Method

n = 12345 count = len(str(abs(n))) print("Digits:", count)




✅ Easiest and most beginner-friendly method.

🔹 Method 4 – Using Recursion

def count_digits(n): n = abs(n) if n < 10: return 1 return 1 + count_digits(n // 10) print(count_digits(12345))









✅ Great for learning recursive logic.

🎯 Output

Digits: 5

🔑 Key Takeaways

  • Use // 10 to remove the last digit step by step.
  • len(str(n)) is the easiest way to count digits.
  • Use abs(n) to handle negative numbers.
  • Special case: 0 has 1 digit.

Solve Any Quadratic Equation in Python Using User Input (Step-by-Step Guide)

 


Mathematics meets programming in one of the most practical ways—solving equations using code.

In this guide, you’ll learn how to build a Python program that takes user input and solves any quadratic equation instantly.

Let’s turn a classic math formula into real-world code 👇


What is a Quadratic Equation?

A quadratic equation looks like this:

ax2+bx+c=0

Where:

  • a, b, c are constants
  • x is the variable we want to find

To solve it, we use the quadratic formula:

x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Understanding the Discriminant

The part inside the square root is called the discriminant:

D=b24acD = b^2 - 4ac

It determines the type of roots:

  • D > 0 → Two real and distinct roots
  • D = 0 → One real root
  • D < 0 → Complex (imaginary) roots

 Python Implementation

Now let’s convert this logic into Python code that takes input from the user. 

import math # taking input a = float(input("Enter a: ")) b = float(input("Enter b: ")) c = float(input("Enter c: ")) # discriminant d = b**2 - 4*a*c # solving if d > 0: x1 = (-b + math.sqrt(d)) / (2*a) x2 = (-b - math.sqrt(d)) / (2*a) print("Two real roots:", x1, x2) elif d == 0: x = -b / (2*a) print("One real root:", x) else: real = -b / (2*a) imag = math.sqrt(-d) / (2*a) print("Complex roots:", real, "+", imag, "i and", real, "-", imag, "i")



















Example Run

Enter a: 1
Enter b: -3
Enter c: 2

Output:

Two real roots: 2.0 1.0

Key Concepts You Learned

  • Taking user input in Python
  • Using the math module
  • Applying mathematical formulas in code
  • Handling different cases (real & complex roots)

 Pro Tip

Always make sure:

  • a ≠ 0, otherwise it's not a quadratic equation
  • Use float() to handle decimal values

Conclusion

With just a few lines of Python, you can solve any quadratic equation automatically. This is a perfect beginner project that combines math + programming logic.

Once you understand this, you can extend it further:

  • Build a GUI calculator 🖥️
  • Plot graphs of equations 📊
  • Turn it into a web app 🌐

Python Coding Challenge - Question with Answer (ID -300426)

 


Explanation:

🔹 Step 1: Understand Boolean Values in Python
In Python, booleans are treated like integers:
True = 1
False = 0

🔹 Step 2: Replace Boolean with Integer Values
print(1 + 0 * 5)

🔹 Step 3: Follow Operator Precedence
Python follows BODMAS/PEMDAS
Multiplication (*) happens before addition (+)

So:

0 * 5 = 0

🔹 Step 4: Perform Addition
1 + 0 = 1

🔹 Step 5: Final Output
print(1)

👉 Output:

1


Wednesday, 29 April 2026

🚀 Day 34/150 – Armstrong Number in Python

 

🚀 Day 34/150 – Armstrong Number in Python

An Armstrong number is a number that is equal to the sum of its own digits raised to the power of total digits.
Example: 153 = 1³ + 5³ + 3³ = 153

Let’s explore different ways to check Armstrong number in Python 👇

🔹 Method 1 – Using while Loop

n = 153 temp = n digits = len(str(n)) total = 0 while n > 0: digit = n % 10 total += digit ** digits n //= 10 if temp == total: print("Armstrong Number") else: print("Not Armstrong Number")







✅ Best numeric method.

🔹 Method 2 – Taking User Input

n = int(input("Enter a number: ")) temp = n digits = len(str(n)) total = 0 while n > 0: digit = n % 10 total += digit ** digits n //= 10 print("Armstrong Number" if temp == total else "Not Armstrong Number")






✅ Useful for dynamic programs.

🔹 Method 3 – Using for Loop + String

n = 153 digits = len(str(n)) total = sum(int(i) ** digits for i in str(n)) if n == total: print("Armstrong Number") else: print("Not Armstrong Number")





✅ Short and clean method.

🔹 Method 4 – Using Function

def is_armstrong(n): digits = len(str(n)) total = sum(int(i) ** digits for i in str(n)) return n == total print(is_armstrong(153))




✅ Reusable for projects.

📌 Example Output

For 153

Armstrong Number

🎯 Best Method?

while loop → best for logic building
for loop + string → shortest method
function → reusable and clean

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (255) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (29) Azure (10) BI (10) Books (262) Bootcamp (11) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (30) data (5) Data Analysis (32) Data Analytics (22) data management (15) Data Science (354) Data Strucures (17) Deep Learning (159) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (73) Git (10) Google (51) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (42) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (293) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (14) PHP (20) Projects (33) pytho (1) Python (1334) Python Coding Challenge (1132) Python Mathematics (1) Python Mistakes (51) Python Quiz (492) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (49) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)