Monday, 30 March 2026

๐Ÿš€ Day 8/150 – Check Even or Odd Number in Python


Welcome back to the 150 Python Programs: From Beginner to Advanced series.

Today we will learn how to check whether a number is even or odd in Python.

This is one of the most fundamental problems in programming and helps build logic.


๐Ÿง  Problem Statement

๐Ÿ‘‰ Write a Python program to check if a number is even or odd.

1️⃣ Method 1 – Using Modulus Operator %

The most common and easiest way.

num = 7 if num % 2 == 0: print("Even number") else: print("Odd number")





Output

Odd number

✔ Simple and widely used
✔ Best for beginners

2️⃣ Method 2 – Taking User Input

Make the program interactive.

num = int(input("Enter a number: ")) if num % 2 == 0: print("Even number") else: print("Odd number")






✔ Works for any number

✔ Real-world usage

3️⃣ Method 3 – Using a Function

Functions make code reusable and clean.

def check_even_odd(n): if n % 2 == 0: return "Even" else: return "Odd" print(check_even_odd(7))







✔ Reusable logic

✔ Clean structure

4️⃣ Method 4 – Using Bitwise Operator

A more advanced and efficient way.

num = 7 if num & 1: print("Odd number") else: print("Even number")




✔ Faster at low level
✔ Used in performance-critical code

๐ŸŽฏ Key Takeaways

Today you learned:

  • Using % operator to check even/odd
  • Taking user input
  • Writing reusable functions
  • Using bitwise operator &


๐Ÿš€ Day 7/150 – Swap Two Variables in Python

 

Today we will learn how to swap two variables in Python using different methods.

Swapping is a very common concept used in:

  • Sorting algorithms
  • Data manipulation
  • Problem solving

๐Ÿง  Problem Statement

๐Ÿ‘‰ Write a Python program to swap two variables.

1️⃣ Method 1 – Using a Temporary Variable

This is the most traditional method.

a = 5 b = 10 temp = a a = b b = temp print("a =", a) print("b =", b)









✔ Easy to understand

✔ Good for beginners

2️⃣ Method 2 – Pythonic Way (Tuple Swapping)

Python provides a simple and elegant way to swap variables.


a = 5 b = 10 a, b = b, a print("a =", a) print("b =", b)




✔ Short and clean
✔ Most recommended method

3️⃣ Method 3 – Using Addition and Subtraction

Swap values without using a third variable.

a = 5 b = 10 a = a + b b = a - b a = a - b print("a =", a) print("b =", b)









✔ No extra variable needed

⚠️ Can cause overflow with very large numbers

4️⃣ Method 4 – Using Multiplication and Division

Another method without a temporary variable.

a = 5 b = 10 a = a * b b = a / b a = a / b print("a =", a) print("b =", b)





✔ Works without extra variable
⚠️ Avoid if values can be zero (division issue)

⚠️ Important Note

  • Avoid division method when b = 0
  • Prefer tuple swapping for clean and safe code

๐ŸŽฏ Key Takeaways

Today you learned:

  • Multiple ways to swap variables
  • Python’s tuple unpacking
  • Logic behind swapping without extra variables

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

 





Explanation:

๐Ÿ”น 1. Importing pandas (implicit step)

Before this code runs, you usually need:

import pandas as pd
✅ Explanation:
pandas is a powerful Python library used for data manipulation.
pd is just an alias (short name) for pandas to make typing easier.

๐Ÿ”น 2. Creating the DataFrame
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
✅ Explanation:
pd.DataFrame() creates a table-like structure (rows and columns).

The input is a dictionary:
'A': [1, 2] → Column A with values 1 and 2
'B': [3, 4] → Column B with values 3 and 4
๐Ÿ“Š Resulting DataFrame:
index A B
0 1 3
1 2 4
๐Ÿง  Key Points:
Columns are A and B
Default index starts from 0

๐Ÿ”น 3. Accessing Data using .loc
print(df.loc[0, 'A'])
✅ Explanation:
.loc[] is used to access data by label (row index + column name)
๐Ÿ“Œ Breakdown:
0 → Row index
'A' → Column name

So:
๐Ÿ‘‰ df.loc[0, 'A'] means
➡️ “Get value from row 0 and column A”

๐Ÿ”น 4. Output
1

AI Agents and Applications: With LangChain, LangGraph, and MCP

 


Artificial intelligence is rapidly evolving from simple models that generate text to intelligent agents that can reason, act, and interact with real-world systems. This shift marks the beginning of a new era—agentic AI, where systems don’t just respond, but actively perform tasks.

The book AI Agents and Applications: With LangChain, LangGraph, and MCP by Roberto Infante provides a hands-on roadmap for building these advanced systems. It focuses on modern tools like LangChain, LangGraph, and the Model Context Protocol (MCP) to create scalable, production-ready AI applications.


The Rise of AI Agents

Traditional AI systems are reactive—they respond to prompts. AI agents, however, are proactive systems that can:

  • Plan multi-step tasks
  • Use external tools (APIs, databases)
  • Maintain memory and context
  • Execute actions autonomously

These capabilities are transforming AI into digital collaborators, capable of handling complex workflows across industries.


What Makes This Book Unique?

This book stands out because it focuses on practical, real-world implementation rather than just theory.

It teaches how to build:

  • Intelligent chatbots with memory
  • Semantic search engines
  • Automated research assistants
  • Multi-agent systems for complex workflows

The emphasis is on creating production-ready AI systems, not just experiments.


Core Technologies Explained

1. LangChain – The Foundation of LLM Applications

LangChain is a framework used to build applications powered by large language models.

It enables developers to:

  • Connect LLMs with external data
  • Build modular AI components
  • Create pipelines for tasks like summarization and Q&A

In the book, LangChain acts as the building block for intelligent applications.


2. LangGraph – Orchestrating AI Workflows

LangGraph takes AI development further by enabling structured, multi-step workflows.

It allows developers to:

  • Design agent workflows as graphs
  • Manage state and memory across tasks
  • Coordinate complex decision-making processes

This is crucial for building autonomous agents that can handle multi-step reasoning tasks.


3. MCP (Model Context Protocol) – Connecting AI to the Real World

MCP is a modern standard that allows AI agents to interact with external tools and systems.

It enables:

  • Integration with APIs and services
  • Tool-based execution (e.g., sending emails, querying databases)
  • Modular and reusable AI architectures

MCP acts as a bridge between AI models and real-world actions, making agents truly useful.


Key Concepts Covered in the Book

Prompt and Context Engineering

The book emphasizes how to design prompts and manage context effectively to:

  • Reduce hallucinations
  • Improve accuracy
  • Ensure reliable outputs

This is foundational for building trustworthy AI systems.


Retrieval-Augmented Generation (RAG)

RAG is a powerful technique that combines LLMs with external data sources.

It enables:

  • Accurate question answering
  • Document summarization
  • Semantic search

The book explores both basic and advanced RAG techniques for real-world applications.


Tool-Based Agents

Modern AI agents are not limited to text—they can use tools dynamically.

Examples include:

  • Searching the web
  • Querying databases
  • Calling APIs

These agents adapt in real time based on user needs, making them highly flexible.


Multi-Agent Systems

One of the most advanced topics covered is multi-agent collaboration.

In these systems:

  • Multiple AI agents work together
  • Tasks are divided and coordinated
  • Complex workflows are executed efficiently

This mirrors how teams work in real-world organizations.


From Simple Models to Agentic Systems

The book follows a progression:

  1. Basic prompt engineering
  2. Building simple LLM applications
  3. Adding memory and context
  4. Integrating tools and APIs
  5. Designing multi-agent workflows

This structured approach helps learners move from beginner-level AI to advanced agent systems.


Real-World Applications

The techniques in this book are directly applicable to modern AI use cases:

  • Customer support agents
  • Automated research assistants
  • Code generation tools
  • Business workflow automation

AI agents are increasingly being used to automate tasks across industries, from software development to finance.


Skills You Can Gain

By learning from this book, you can develop:

  • Expertise in LangChain and LangGraph
  • Ability to build agent-based AI systems
  • Knowledge of RAG and prompt engineering
  • Skills in integrating AI with real-world tools
  • Understanding of scalable AI architectures

These are cutting-edge skills in the AI engineering ecosystem.


Who Should Read This Book

This book is ideal for:

  • AI and machine learning engineers
  • Software developers building AI applications
  • Data scientists exploring LLMs
  • Professionals interested in agentic AI

Some familiarity with Python and basic AI concepts is recommended.


The Future of AI: Agentic Systems

The book reflects a major trend in AI:

The shift from static models → dynamic, autonomous agents

Future AI systems will:

  • Collaborate with humans
  • Automate complex workflows
  • Interact with multiple systems seamlessly
  • Continuously learn and adapt

Agent-based architectures are expected to become the standard for AI applications.


Hard Copy: AI Agents and Applications: With LangChain, LangGraph, and MCP

Kindly: AI Agents and Applications: With LangChain, LangGraph, and MCP

Conclusion

AI Agents and Applications: With LangChain, LangGraph, and MCP is a forward-looking guide that captures the essence of modern AI development. It goes beyond traditional machine learning and introduces a new paradigm where AI systems can think, act, and collaborate.

By combining frameworks like LangChain, orchestration tools like LangGraph, and integration standards like MCP, the book provides everything needed to build intelligent, real-world AI applications.

As the industry moves toward agentic AI, this book equips readers with the knowledge and skills to stay ahead—transforming them from developers into architects of intelligent systems.

Introduction to Data Science for Engineering Students

 


In today’s technology-driven world, engineers are no longer limited to traditional design and analysis—they are increasingly expected to work with data, build models, and derive insights. Data science has become a critical skill across engineering disciplines, from mechanical and electrical to civil and chemical engineering.

The book Introduction to Data Science for Engineering Students is designed specifically to bridge this gap. It provides a structured introduction to data science concepts tailored for engineering learners, combining mathematical foundations, programming, and real-world problem-solving.


Why Data Science is Essential for Engineers

Engineering has always been about solving problems. Today, many of those problems involve large datasets, complex systems, and uncertainty.

Data science helps engineers:

  • Analyze experimental and sensor data
  • Optimize systems and processes
  • Build predictive models
  • Make data-driven decisions

Modern industries—from manufacturing to energy—rely heavily on data analytics and machine learning, making data science a must-have skill for engineers.


Foundations of Data Science

The book emphasizes a strong foundation in the core components of data science.

Key Areas Include:

  • Programming (Python or R): essential for handling and analyzing data
  • Mathematics and statistics: for modeling and inference
  • Data handling: cleaning, transforming, and organizing datasets
  • Visualization: presenting insights effectively

Python is often highlighted as a preferred language due to its simplicity and rich ecosystem of libraries like NumPy, Pandas, and Scikit-learn


The Data Science Workflow for Engineers

A major strength of this book is its focus on the end-to-end workflow, which aligns closely with engineering problem-solving.

Typical Workflow:

  1. Problem Definition
    Understanding the engineering challenge
  2. Data Collection
    Gathering data from sensors, experiments, or simulations
  3. Data Cleaning
    Handling missing values and inconsistencies
  4. Exploratory Data Analysis (EDA)
    Identifying patterns and trends
  5. Model Building
    Applying machine learning or statistical models
  6. Evaluation and Interpretation
    Validating results and drawing conclusions

This structured approach ensures that solutions are both accurate and practical.


Machine Learning for Engineering Applications

The book introduces machine learning techniques relevant to engineering problems.

Common Methods Include:

  • Regression: predicting continuous variables (e.g., temperature, pressure)
  • Classification: identifying categories (e.g., fault detection)
  • Clustering: grouping similar data points

Machine learning provides tools for analyzing complex systems and making predictions based on data, which is increasingly important in engineering research and industry


Real-World Engineering Applications

Data science is applied across various engineering domains:

Mechanical Engineering

  • Predictive maintenance
  • Performance optimization

Electrical Engineering

  • Signal processing
  • Fault detection

Civil Engineering

  • Traffic flow analysis
  • Structural health monitoring

Chemical Engineering

  • Process optimization
  • Quality control

These applications show how data science enhances traditional engineering methods.


Bridging Theory and Practice

One of the key goals of the book is to connect theoretical concepts with practical implementation.

It encourages learners to:

  • Work with real datasets
  • Build models from scratch
  • Interpret results in an engineering context

This approach ensures that students gain not just knowledge, but also practical skills for real-world problems.


Tools and Technologies

The book introduces essential tools used in data science:

  • Python / R for programming
  • Jupyter Notebook for interactive analysis
  • Libraries for machine learning and visualization

These tools enable engineers to build scalable and efficient data-driven solutions.


Skills You Can Gain

By studying this book, engineering students can develop:

  • Data analysis and visualization skills
  • Understanding of machine learning algorithms
  • Programming proficiency for data science
  • Problem-solving using data-driven approaches
  • Ability to apply AI techniques in engineering contexts

These skills are highly valuable in both academia and industry.


Who Should Read This Book

This book is ideal for:

  • Engineering students (all branches)
  • Beginners in data science
  • Researchers working with experimental data
  • Professionals transitioning into AI and analytics

It is especially useful for those who want to combine engineering knowledge with modern data science techniques.


The Future of Data Science in Engineering

The integration of data science into engineering is accelerating rapidly.

Future trends include:

  • Smart manufacturing and Industry 4.0
  • AI-driven engineering design
  • Autonomous systems and robotics
  • Real-time data analytics from IoT devices

Engineers who understand data science will be better equipped to lead innovation in these areas.


Hard Copy: Introduction to Data Science for Engineering Students

Kindle: Introduction to Data Science for Engineering Students

Conclusion

Introduction to Data Science for Engineering Students provides a strong foundation for engineers entering the world of data-driven technology. By combining programming, statistics, and machine learning with practical applications, it prepares learners to solve complex engineering problems using modern tools.

As industries continue to evolve, the ability to work with data will become a defining skill for engineers. This book serves as an essential starting point for anyone looking to merge engineering expertise with the power of data science.

Sunday, 29 March 2026

Python Coding challenge - Day 1109| What is the output of the following Python Code?

 


Code Explanation:

1️⃣ Defining the Class
class A:

Explanation

A class named A is created.
It will have special string representation methods.

2️⃣ Defining __str__
def __str__(self):
    return "STR"

Explanation

__str__ defines human-readable representation.
Used when:
print(a)
str(a)

3️⃣ Defining __repr__
def __repr__(self):
    return "REPR"

Explanation

__repr__ defines official / developer representation.
Used in:
lists
debugging
interactive shell

4️⃣ Creating Object
a = A()

Explanation

Creates an instance a of class A.

5️⃣ Printing Inside List
print([a])

Explanation ⚠️ IMPORTANT

When printing a list:
Python uses __repr__, NOT __str__

๐Ÿ‘‰ So internally:

repr(a)
Which returns:
"REPR"

๐Ÿ“ค Final Output
['REPR']


Python Coding challenge - Day 1111| What is the output of the following Python Code?

 




Code Explanation:

1️⃣ Importing Threading Module

import threading

Explanation

Imports Python’s built-in threading module.
Used to create and manage threads.

2️⃣ Defining Task Function
def task():
    print("X")

Explanation

A function task is defined.
This will run inside a thread.
It simply prints:
X

3️⃣ Creating a Thread Object
t = threading.Thread(target=task)

Explanation

A thread t is created.
target=task means:
When thread runs → it executes task().

4️⃣ Starting the Thread (First Time)
t.start()

Explanation

Starts execution of the thread.
Internally calls:
task()

๐Ÿ‘‰ Output:

X

5️⃣ Waiting for Thread to Finish
t.join()

Explanation

Main thread waits until thread t completes.
Ensures thread has fully finished execution.

6️⃣ Starting the Same Thread Again ❌
t.start()

Explanation ⚠️ IMPORTANT

You are trying to restart the same thread object.
This is NOT allowed in Python.

๐Ÿ‘‰ A thread can be started only once.

❌ What Happens?
Python raises an error:
RuntimeError: threads can only be started once

๐Ÿ“ค Final Output
X
RuntimeError

Python Coding challenge - Day 1112| What is the output of the following Python Code?

 


Code Explanation:

1️⃣ Importing Threading Module
import threading

Explanation

Imports Python’s threading module.
Used to create and run threads.

2️⃣ Global Variable Declaration
x = 0

Explanation

A global variable x is created.
Initial value:
x = 0

3️⃣ Defining Task Function
def task():

Explanation

Function task will run inside the thread.

4️⃣ Local Variable Inside Function
x = 10

Explanation ⚠️ IMPORTANT

This creates a local variable x inside the function.
It does NOT affect the global variable.

๐Ÿ‘‰ So:

global x = 0   (unchanged)
local x = 10   (inside function only)

5️⃣ Creating Thread
t = threading.Thread(target=task)

Explanation

A thread t is created.
It will execute the task() function.

6️⃣ Starting Thread
t.start()

Explanation

Thread starts executing task().
Inside thread:
x = 10   (local variable)
Global x remains unchanged.

7️⃣ Waiting for Thread to Finish
t.join()

Explanation

Main thread waits until task() completes.

8️⃣ Printing Value
print(x)

Explanation

Prints the global variable x.
Since global x was never modified:

๐Ÿ“ค Final Output
0

Python Coding challenge - Day 1108| What is the output of the following Python Code?

 

Code Explanation:

1️⃣ Defining Class A

class A:

Explanation

A base class A is created.
It contains a method show().

2️⃣ Method in Class A
def show(self, x=1):

Explanation

Method show takes a parameter x.
Default value of x is 1.

3️⃣ Printing Value
print(x)

Explanation

Prints the value of x.

4️⃣ Defining Class B (Inheritance)
class B(A):

Explanation

Class B inherits from class A.
It can use and override methods of A.

5️⃣ Overriding Method in Class B
def show(self, x=2):

Explanation

show() is overridden in class B.
Default value of x is now 2.

6️⃣ Calling Parent Method Using super()
super().show(x)

Explanation

Calls the show() method of class A.
Passes value of x from class B.

7️⃣ Creating Object
b = B()

Explanation

Creates an instance b of class B.

8️⃣ Calling Method
b.show()

Explanation

Calls show() from class B.
Since no argument is passed:
x = 2   (default of class B)
Then:
super().show(2)

9️⃣ Execution in Class A
Parent method receives:
x = 2
Prints:
2

๐Ÿ“ค Final Output
2

Python Coding challenge - Day 1107| What is the output of the following Python Code?

 


Code Explanation:

1️⃣ Defining the Class
class A:

Explanation

A class named A is created.
It will be used to create objects.

2️⃣ Creating a Class Variable
x = 5

Explanation

x is a class variable.
It belongs to the class, not to individual objects.
All objects initially share this value.

3️⃣ Creating First Object
a = A()

Explanation

Creates an instance a of class A.
a can access class variable x.

4️⃣ Creating Second Object
b = A()

Explanation

Creates another instance b.
Both a and b currently share:
x = 5

5️⃣ Modifying Variable via Object
a.x = 10

Explanation ⚠️

This does NOT change the class variable.
Instead, it creates a new instance variable x inside object a.

๐Ÿ‘‰ Now:

A.x = 5      # class variable
a.x = 10     # instance variable (new)
b.x = 5      # still uses class variable

6️⃣ Printing Values
print(A.x, a.x, b.x)

Explanation

A.x → class variable → 5
a.x → instance variable → 10
b.x → no instance variable → uses class variable → 5

๐Ÿ“ค Final Output
5 10 5

Popular Posts

Categories

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

Followers

Python Coding for Kids ( Free Demo for Everyone)