<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Pi Ankit]]></title><description><![CDATA[Pi Ankit]]></description><link>https://ankitpi.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 10:10:14 GMT</lastBuildDate><atom:link href="https://ankitpi.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Arduino DHT11 Temperature & Humidity Monitoring System]]></title><description><![CDATA[This project uses an Arduino UNO and DHT11 sensor to measure temperature and humidity and display the readings on a live web dashboard using Python Flask…]]></description><link>https://ankitpi.hashnode.dev/dht11</link><guid isPermaLink="true">https://ankitpi.hashnode.dev/dht11</guid><dc:creator><![CDATA[Ankit Chapagain]]></dc:creator><pubDate>Tue, 03 Nov 2026 16:42:42 GMT</pubDate><content:encoded><![CDATA[<h1></h1>
<h2>1. Project Overview</h2>
<p>This project uses an <strong>Arduino UNO and DHT11 sensor</strong> to measure temperature and humidity and display the readings on a live web dashboard using Python Flask.</p>
<h3>Technologies Used</h3>
<ul>
<li>Arduino UNO</li>
<li>DHT11 Temperature and Humidity Sensor</li>
<li>Arduino IDE</li>
<li>Python</li>
<li>Flask</li>
<li>PySerial</li>
<li>HTML, CSS and JavaScript</li>
</ul>
<h3>System Architecture</h3>
<pre><code class="language-text">DHT11 Sensor
     |
     v
Arduino UNO
     |
     v
USB Serial Communication
     |
     v
Python Flask Application
     |
     v
Web Dashboard
     |
     v
Live Temperature &amp; Humidity
</code></pre>
<hr />
<h2>2. Hardware Requirements</h2>
<table>
<thead>
<tr>
<th>Component</th>
<th align="right">Quantity</th>
</tr>
</thead>
<tbody><tr>
<td>Arduino UNO</td>
<td align="right">1</td>
</tr>
<tr>
<td>DHT11 Sensor</td>
<td align="right">1</td>
</tr>
<tr>
<td>Jumper Wires</td>
<td align="right">3</td>
</tr>
<tr>
<td>USB Cable</td>
<td align="right">1</td>
</tr>
<tr>
<td>Computer/Laptop</td>
<td align="right">1</td>
</tr>
</tbody></table>
<h3>DHT11 Connections</h3>
<table>
<thead>
<tr>
<th>DHT11 Pin</th>
<th>Arduino UNO</th>
</tr>
</thead>
<tbody><tr>
<td>VCC</td>
<td>5V</td>
</tr>
<tr>
<td>DATA</td>
<td>Digital Pin 2</td>
</tr>
<tr>
<td>GND</td>
<td>GND</td>
</tr>
</tbody></table>
<p><em>For a bare four-pin DHT11 sensor, check its pinout and use the required pull-up resistor. Three-pin modules often include this resistor.</em></p>
<hr />
<h2>3. Arduino IDE Setup</h2>
<h3>Step 1: Install Arduino IDE</h3>
<p>Download Arduino IDE:</p>
<p><a href="https://www.arduino.cc/en/software">https://www.arduino.cc/en/software</a></p>
<p>Install and open Arduino IDE.</p>
<h3>Step 2: Install DHT11 Library</h3>
<ol>
<li>Open Arduino IDE.</li>
<li>Navigate to <strong>Sketch → Include Library → Manage Libraries</strong>.</li>
<li>Search for <code>DHT sensor library</code>.</li>
<li>Install <strong>DHT sensor library by Adafruit</strong>.</li>
<li>Install <strong>Adafruit Unified Sensor</strong> if requested.</li>
</ol>
<h3>Step 3: Arduino Code</h3>
<p>Create a new Arduino sketch and upload the following code.</p>
<pre><code class="language-cpp">#include &lt;DHT.h&gt;

// Sensor configuration
#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {

    // Start serial communication
    Serial.begin(9600);

    // Initialize DHT11
    dht.begin();
}

void loop() {

    // Read sensor values
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    // Check sensor readings
    if (isnan(temperature) || isnan(humidity)) {

        Serial.println("ERROR");

    }
    else {

        // Send data to Python
        Serial.print(temperature);
        Serial.print(",");
        Serial.println(humidity);

    }

    delay(2000);
}
</code></pre>
<h3>Expected Serial Output</h3>
<pre><code class="language-text">28.00,65.00
29.00,64.00
30.00,63.00
</code></pre>
<p>The first value represents temperature in Celsius, and the second represents humidity in percentage.</p>
<hr />
<h2>4. Python Environment Setup</h2>
<h3>Step 1: Install Python</h3>
<p>Download Python from:</p>
<p><a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a></p>
<p>During installation, select <strong>Add Python to PATH</strong>.</p>
<p>Verify installation:</p>
<pre><code class="language-bash">python --version
</code></pre>
<h3>Step 2: Create Project Folder</h3>
<p>Open PowerShell or Command Prompt.</p>
<pre><code class="language-powershell">mkdir DHT11_Website
cd DHT11_Website
</code></pre>
<h3>Step 3: Create Python Virtual Environment</h3>
<p>A virtual environment keeps project dependencies separate from other Python projects.</p>
<pre><code class="language-bash">python -m venv venv
</code></pre>
<h3>Step 4: Activate Virtual Environment</h3>
<p><strong>Windows PowerShell:</strong></p>
<pre><code class="language-powershell">.\venv\Scripts\Activate.ps1
</code></pre>
<p>If PowerShell blocks activation, run:</p>
<pre><code class="language-powershell">Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
</code></pre>
<p>Then activate again:</p>
<pre><code class="language-powershell">.\venv\Scripts\Activate.ps1
</code></pre>
<p><strong>Windows Command Prompt:</strong></p>
<pre><code class="language-cmd">venv\Scripts\activate.bat
</code></pre>
<p>After successful activation, you should see:</p>
<pre><code class="language-text">(venv) C:\...\DHT11_Website&gt;
</code></pre>
<h3>Step 5: Install Required Libraries</h3>
<pre><code class="language-bash">pip install flask pyserial
</code></pre>
<p>Verify installed packages:</p>
<pre><code class="language-bash">pip list
</code></pre>
<h3>Step 6: Save Dependencies</h3>
<pre><code class="language-bash">pip freeze &gt; requirements.txt
</code></pre>
<hr />
<h2>5. Project Structure</h2>
<p>The project will contain one Python application file.</p>
<pre><code class="language-text">DHT11_Website/
│
├── venv/
│
├── app.py
│
└── requirements.txt
</code></pre>
<p>The HTML, CSS and JavaScript code will be included inside <code>app.py</code>, so a separate HTML file is not required.</p>
<hr />
<h2>6. Create the Python Application</h2>
<p>Create a file named <code>app.py</code>.</p>
<p>Copy the following complete code:</p>
<pre><code class="language-python">from flask import Flask, jsonify, render_template_string
import serial
import threading
import time

app = Flask(__name__)

# Arduino Configuration
SERIAL_PORT = "COM3"
BAUD_RATE = 9600

# Sensor Variables
temperature = 0
humidity = 0

connection_status = "Disconnected"
last_updated = "--"


# =====================================
# ARDUINO SERIAL COMMUNICATION
# =====================================

def read_arduino():

    global temperature, humidity
    global connection_status, last_updated

    while True:

        try:

            print("Connecting to Arduino...")

            arduino = serial.Serial(
                SERIAL_PORT,
                BAUD_RATE,
                timeout=2
            )

            time.sleep(2)

            connection_status = "Connected"

            print("Arduino Connected!")

            while True:

                line = arduino.readline().decode(
                    "utf-8",
                    errors="ignore"
                ).strip()

                if not line or line == "ERROR":
                    continue

                try:

                    values = line.split(",")

                    if len(values) == 2:

                        temp = float(values[0])
                        hum = float(values[1])

                        temperature = temp
                        humidity = hum

                        last_updated = time.strftime("%H:%M:%S")

                        print(
                            f"Temperature: {temp} C | "
                            f"Humidity: {hum} %"
                        )

                except ValueError:

                    continue

        except Exception as error:

            connection_status = "Disconnected"

            print("Arduino Error:", error)

            time.sleep(3)


# =====================================
# HTML DASHBOARD
# =====================================

HTML_PAGE = """

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;

    &lt;title&gt;DHT11 Monitoring System&lt;/title&gt;

    &lt;meta name="viewport"
          content="width=device-width, initial-scale=1"&gt;

    &lt;style&gt;

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background: #eef2f7;
            color: #172554;
        }

        header {
            background: #172554;
            color: white;
            padding: 30px 15px;
            text-align: center;
        }

        header h1 {
            margin: 0 0 10px;
        }

        .container {
            max-width: 900px;
            margin: 50px auto;
            padding: 15px;
        }

        .cards {
            display: flex;
            justify-content: center;
            gap: 25px;
            flex-wrap: wrap;
        }

        .card {
            background: white;
            width: 300px;
            padding: 35px 20px;
            border-radius: 18px;
            text-align: center;
            box-shadow: 0 5px 20px #0001;
        }

        .icon {
            font-size: 45px;
        }

        .value {
            font-size: 48px;
            font-weight: bold;
            margin: 20px 0;
        }

        .temperature {
            color: #ef4444;
        }

        .humidity {
            color: #2563eb;
        }

        .status-box {
            background: white;
            padding: 22px;
            border-radius: 15px;
            margin-top: 30px;
            text-align: center;
        }

        .connected {
            color: #16a34a;
        }

        .disconnected {
            color: #dc2626;
        }

        footer {
            text-align: center;
            padding: 25px;
            color: #64748b;
        }

    &lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

    &lt;header&gt;

        &lt;h1&gt;🌡️ DHT11 Monitoring System&lt;/h1&gt;

        &lt;p&gt;Live Temperature and Humidity Dashboard&lt;/p&gt;

    &lt;/header&gt;


    &lt;div class="container"&gt;

        &lt;div class="cards"&gt;

            &lt;div class="card"&gt;

                &lt;div class="icon"&gt;🌡️&lt;/div&gt;

                &lt;h2&gt;Temperature&lt;/h2&gt;

                &lt;div class="value temperature"
                     id="temperature"&gt;

                    -- °C

                &lt;/div&gt;

                &lt;p&gt;Room Temperature&lt;/p&gt;

            &lt;/div&gt;


            &lt;div class="card"&gt;

                &lt;div class="icon"&gt;💧&lt;/div&gt;

                &lt;h2&gt;Humidity&lt;/h2&gt;

                &lt;div class="value humidity"
                     id="humidity"&gt;

                    -- %

                &lt;/div&gt;

                &lt;p&gt;Air Humidity&lt;/p&gt;

            &lt;/div&gt;

        &lt;/div&gt;


        &lt;div class="status-box"&gt;

            &lt;h3&gt;

                Arduino Status:

                &lt;span id="status" class="disconnected"&gt;

                    Checking...

                &lt;/span&gt;

            &lt;/h3&gt;

            &lt;p&gt;

                Last Updated:

                &lt;span id="updated"&gt;--&lt;/span&gt;

            &lt;/p&gt;

        &lt;/div&gt;

    &lt;/div&gt;


    &lt;footer&gt;

        Arduino UNO + DHT11 | Python Flask IoT Dashboard

    &lt;/footer&gt;


    &lt;script&gt;

        async function updateData() {

            try {

                const response = await fetch("/data");

                const data = await response.json();


                document.getElementById("temperature").innerText =
                    data.temperature + " °C";


                document.getElementById("humidity").innerText =
                    data.humidity + " %";


                const status =
                    document.getElementById("status");


                status.innerText = data.status;


                status.className =
                    data.status === "Connected"
                    ? "connected"
                    : "disconnected";


                document.getElementById("updated").innerText =
                    data.updated;

            }

            catch (error) {

                document.getElementById("status").innerText =
                    "Connection Error";

            }

        }


        updateData();

        // Update every two seconds
        setInterval(updateData, 2000);

    &lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;

"""


# =====================================
# FLASK ROUTES
# =====================================

@app.route("/")
def home():

    return render_template_string(HTML_PAGE)


@app.route("/data")
def get_data():

    return jsonify({

        "temperature": temperature,

        "humidity": humidity,

        "status": connection_status,

        "updated": last_updated

    })


# =====================================
# START APPLICATION
# =====================================

if __name__ == "__main__":

    thread = threading.Thread(
        target=read_arduino,
        daemon=True
    )

    thread.start()

    app.run(
        host="127.0.0.1",
        port=5000,
        debug=False
    )
</code></pre>
<hr />
<h2>7. Configure Arduino COM Port</h2>
<p>Before running the application, identify the Arduino COM port.</p>
<ol>
<li>Open Arduino IDE.</li>
<li>Connect Arduino UNO.</li>
<li>Select <strong>Tools → Port</strong>.</li>
<li>Note the COM port number.</li>
</ol>
<p>For example:</p>
<pre><code class="language-python">SERIAL_PORT = "COM3"
</code></pre>
<p>If your Arduino uses COM5, change it to:</p>
<pre><code class="language-python">SERIAL_PORT = "COM5"
</code></pre>
<p><strong>Important:</strong> Close Arduino IDE Serial Monitor before running the Python application because both applications cannot normally access the same serial port simultaneously.</p>
<hr />
<h2>8. Run the Application</h2>
<p>Make sure your virtual environment is activated.</p>
<pre><code class="language-bash">python app.py
</code></pre>
<p>Expected terminal output:</p>
<pre><code class="language-text">Connecting to Arduino...
Arduino Connected!

Temperature: 28.0 C | Humidity: 65.0 %
Temperature: 29.0 C | Humidity: 64.0 %

Running on http://127.0.0.1:5000
</code></pre>
<p>Open your web browser:</p>
<pre><code class="language-text">http://127.0.0.1:5000
</code></pre>
<p>Your live dashboard will display the temperature, humidity and Arduino connection status.</p>
<hr />
<h2>9. Troubleshooting</h2>
<table>
<thead>
<tr>
<th>Problem</th>
<th>Possible Solution</th>
</tr>
</thead>
<tbody><tr>
<td>COM port error</td>
<td>Check the correct Arduino COM port</td>
</tr>
<tr>
<td>Access denied</td>
<td>Close Arduino Serial Monitor</td>
</tr>
<tr>
<td>Arduino disconnected</td>
<td>Check USB cable and connection</td>
</tr>
<tr>
<td>No sensor readings</td>
<td>Check DHT11 wiring and library installation</td>
</tr>
<tr>
<td>Website not opening</td>
<td>Check whether Flask is running on port 5000</td>
</tr>
<tr>
<td>Python module not found</td>
<td>Activate virtual environment and install dependencies</td>
</tr>
</tbody></table>
<hr />
<h2>10. Useful Commands</h2>
<table>
<thead>
<tr>
<th>Task</th>
<th>Command</th>
</tr>
</thead>
<tbody><tr>
<td>Create virtual environment</td>
<td><code>python -m venv venv</code></td>
</tr>
<tr>
<td>Activate environment</td>
<td><code>venv\Scripts\activate</code></td>
</tr>
<tr>
<td>Install Flask</td>
<td><code>pip install flask</code></td>
</tr>
<tr>
<td>Install PySerial</td>
<td><code>pip install pyserial</code></td>
</tr>
<tr>
<td>Save dependencies</td>
<td><code>pip freeze &gt; requirements.txt</code></td>
</tr>
<tr>
<td>Run application</td>
<td><code>python app.py</code></td>
</tr>
<tr>
<td>Deactivate environment</td>
<td><code>deactivate</code></td>
</tr>
</tbody></table>
<hr />
<h2>11. Future Improvements</h2>
<p>After completing the basic project, students can extend it with:</p>
<ol>
<li>Live temperature and humidity graphs.</li>
<li>Historical sensor data storage using SQLite.</li>
<li>Download sensor readings as CSV.</li>
<li>Temperature threshold alerts.</li>
<li>Multiple sensor monitoring.</li>
<li>Professional IoT dashboard design.</li>
<li>Remote access through a suitable network deployment.</li>
</ol>
<p><strong>Project Conclusion:</strong> This project demonstrates how Arduino hardware, sensor technology, serial communication and Python web development can be integrated to create a simple real-time IoT monitoring system.</p>
]]></content:encoded></item><item><title><![CDATA[Day 4 of python]]></title><description><![CDATA[A dictionary is used to store data in key-value pairs. Example: Here: Dictionary is useful when we want to store related information together. Example…]]></description><link>https://ankitpi.hashnode.dev/day-4-of-python</link><guid isPermaLink="true">https://ankitpi.hashnode.dev/day-4-of-python</guid><dc:creator><![CDATA[Ankit Chapagain]]></dc:creator><pubDate>Sat, 23 May 2026 04:15:11 GMT</pubDate><content:encoded><![CDATA[<h1>1. Dictionary Concept</h1>
<p>A <strong>dictionary</strong> is used to store data in <strong>key-value pairs</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">student = {
    "name": "Ram",
    "age": 18,
    "marks": 75
}
</code></pre>
<p>Here:</p>
<pre><code class="language-plaintext">"name"  is key, "Ram" is value
"age"   is key, 18 is value
"marks" is key, 75 is value
</code></pre>
<p>Dictionary is useful when we want to store related information together.</p>
<p>Example:</p>
<pre><code class="language-plaintext">One student has name, age, and marks.
So we can store these details in one dictionary.
</code></pre>
<hr />
<h1>2. Accessing Dictionary Values</h1>
<pre><code class="language-plaintext">student = {
    "name": "Ram",
    "age": 18,
    "marks": 75
}

print(student["name"])
print(student["age"])
print(student["marks"])
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Ram
18
75
</code></pre>
<hr />
<h1>3. Updating Dictionary Values</h1>
<pre><code class="language-plaintext">student = {
    "name": "Ram",
    "marks": 75
}

student["marks"] = 85

print(student)
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">{'name': 'Ram', 'marks': 85}
</code></pre>
<p>Here, marks changed from <code>75</code> to <code>85</code>.</p>
<hr />
<h1>4. Simple Dictionary Exercise</h1>
<h2>Question</h2>
<p>Create a dictionary named <code>book</code>.</p>
<p>It should store:</p>
<pre><code class="language-plaintext">title
author
price
</code></pre>
<p>Then print all details.</p>
<h2>Solution</h2>
<pre><code class="language-plaintext">book = {
    "title": "Python Basics",
    "author": "Ram",
    "price": 500
}

print("Title:", book["title"])
print("Author:", book["author"])
print("Price:", book["price"])
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Title: Python Basics
Author: Ram
Price: 500
</code></pre>
<hr />
<h1>5. Mini Project: Student Management System Using Dictionary</h1>
<h2>Project Goal</h2>
<p>Create a simple program that can:</p>
<pre><code class="language-plaintext">1\. Add student details
2. View student details
3. Update marks
4. Check pass or fail
5. Exit
</code></pre>
<p>This project uses:</p>
<pre><code class="language-plaintext">Dictionary
Function
Input
If else
While loop
Try except
</code></pre>
<p>This is a good continuation from Day 3 because students already studied dictionary, exception handling, file handling, and login using file handling.</p>
<hr />
<h1>6. Full Code</h1>
<pre><code class="language-plaintext">student = {
    "name": "",
    "age": 0,
    "marks": 0
}

def add_student():
    try:
        name = input("Enter student name: ")
        age = int(input("Enter student age: "))
        marks = float(input("Enter student marks: "))

        student["name"] = name
        student["age"] = age
        student["marks"] = marks

        print("Student details added successfully")

    except ValueError:
        print("Please enter valid number for age and marks")

def view_student():
    if student["name"] == "":
        print("No student details found")
    else:
        print("\n--- Student Details ---")
        print("Name:", student["name"])
        print("Age:", student["age"])
        print("Marks:", student["marks"])

def update_marks():
    if student["name"] == "":
        print("No student details found")
    else:
        try:
            new_marks = float(input("Enter new marks: "))
            student["marks"] = new_marks
            print("Marks updated successfully")

        except ValueError:
            print("Please enter valid marks")

def check_result():
    if student["name"] == "":
        print("No student details found")
    else:
        if student["marks"] &gt;= 40:
            print(student["name"], "has passed")
        else:
            print(student["name"], "has failed")

def menu():
    while True:
        print("\n===== Student Management System =====")
        print("1. Add Student")
        print("2. View Student")
        print("3. Update Marks")
        print("4. Check Result")
        print("5. Exit")

        choice = input("Enter your choice: ")

        if choice == "1":
            add_student()

        elif choice == "2":
            view_student()

        elif choice == "3":
            update_marks()

        elif choice == "4":
            check_result()

        elif choice == "5":
            print("Program closed")
            break

        else:
            print("Invalid choice")

menu()
</code></pre>
<hr />
<h1>7. Simple Project Explanation</h1>
<h2>Student Dictionary</h2>
<pre><code class="language-plaintext">student = {
    "name": "",
    "age": 0,
    "marks": 0
}
</code></pre>
<p>This dictionary stores one student's details.</p>
<p>At first, the values are empty.</p>
<p>After adding student, it may look like this:</p>
<pre><code class="language-plaintext">student = {
    "name": "Ram",
    "age": 18,
    "marks": 75
}
</code></pre>
<hr />
<h2>Add Student</h2>
<pre><code class="language-plaintext">student["name"] = name
student["age"] = age
student["marks"] = marks
</code></pre>
<p>This stores user input inside the dictionary.</p>
<hr />
<h2>View Student</h2>
<pre><code class="language-plaintext">print("Name:", student["name"])
print("Age:", student["age"])
print("Marks:", student["marks"])
</code></pre>
<p>This displays the student details.</p>
<hr />
<h2>Update Marks</h2>
<pre><code class="language-plaintext">student["marks"] = new_marks
</code></pre>
<p>This changes old marks into new marks.</p>
<hr />
<h2>Check Result</h2>
<pre><code class="language-plaintext">if student["marks"] &gt;= 40:
    print(student["name"], "has passed")
else:
    print(student["name"], "has failed")
</code></pre>
<p>If marks are <code>40</code> or above, the student passes.</p>
<p>If marks are below <code>40</code>, the student fails.</p>
<hr />
<h1>8. Basic OOP Introduction</h1>
<p>OOP means <strong>Object-Oriented Programming</strong>.</p>
<p>Simple meaning:</p>
<pre><code class="language-plaintext">OOP is a way to keep related data and functions together.
</code></pre>
<p>In dictionary, we write:</p>
<pre><code class="language-plaintext">student = {
    "name": "Ram",
    "age": 18,
    "marks": 75
}
</code></pre>
<p>In OOP, we can create a <code>Student</code> class.</p>
<hr />
<h1>9. Class and Object</h1>
<h2>Class</h2>
<p>A class is a blueprint.</p>
<p>Example:</p>
<pre><code class="language-plaintext">Student class is a blueprint.
</code></pre>
<h2>Object</h2>
<p>An object is created from a class.</p>
<p>Example:</p>
<pre><code class="language-plaintext">Class  -&gt; Student
Object -&gt; Ram
Object -&gt; Sita
</code></pre>
<hr />
<h1>10. Simple OOP Example</h1>
<pre><code class="language-plaintext">class Student:
    def __init__(self, name, age, marks):
        self.name = name
        self.age = age
        self.marks = marks

    def show_details(self):
        print("Name:", self.name)
        print("Age:", self.age)
        print("Marks:", self.marks)

student1 = Student("Ram", 18, 75)

student1.show_details()
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Name: Ram
Age: 18
Marks: 75
</code></pre>
<hr />
<h1>11. Simple OOP Terms</h1>
<table>
<thead>
<tr>
<th>Term</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td>Class</td>
<td>Blueprint</td>
</tr>
<tr>
<td>Object</td>
<td>Real item created from class</td>
</tr>
<tr>
<td>Attribute</td>
<td>Variable inside object</td>
</tr>
<tr>
<td>Method</td>
<td>Function inside class</td>
</tr>
<tr>
<td><code>__init__()</code></td>
<td>Runs automatically when object is created</td>
</tr>
<tr>
<td><code>self</code></td>
<td>Current object</td>
</tr>
</tbody></table>
<hr />
<h1>12. Very Simple Database Introduction</h1>
<p>A database is used to store data permanently.</p>
<p>In dictionary:</p>
<pre><code class="language-plaintext">Data is lost when the program closes.
</code></pre>
<p>In database:</p>
<pre><code class="language-plaintext">Data can be stored permanently.
</code></pre>
<p>SQLite is a simple database that Python can use directly.</p>
<p>We use:</p>
<pre><code class="language-plaintext">import sqlite3
</code></pre>
<p>SQLite creates a file like:</p>
<pre><code class="language-plaintext">school.db
</code></pre>
<hr />
<h1>13. Very Simple SQLite Program</h1>
<p>This program will:</p>
<pre><code class="language-plaintext">1\. Create database
2. Create table
3. Insert one student
4. Select and show students
</code></pre>
<p>Save as:</p>
<pre><code class="language-plaintext">simple_db.py
</code></pre>
<pre><code class="language-plaintext">import sqlite3

# Connect to database
connection = sqlite3.connect("school.db")

# Create cursor
cursor = connection.cursor()

# Create table
cursor.execute("""
CREATE TABLE IF NOT EXISTS students (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    age INTEGER,
    marks REAL
)
""")

# Insert one student
cursor.execute("""
INSERT INTO students (name, age, marks)
VALUES (?, ?, ?)
""", ("Ram", 18, 75))

# Save changes
connection.commit()

# Select data from table
cursor.execute("SELECT * FROM students")

students = cursor.fetchall()

for student in students:
    print(student)

# Close connection
connection.close()
</code></pre>
<p>Output example:</p>
<pre><code class="language-plaintext">(1, 'Ram', 18, 75.0)
</code></pre>
<hr />
<h1>14. Simple Database Code Explanation</h1>
<h2>Import SQLite</h2>
<pre><code class="language-plaintext">import sqlite3
</code></pre>
<p>This lets us use SQLite in Python.</p>
<hr />
<h2>Connect to Database</h2>
<pre><code class="language-plaintext">connection = sqlite3.connect("school.db")
</code></pre>
<p>This creates or opens the database file.</p>
<hr />
<h2>Cursor</h2>
<pre><code class="language-plaintext">cursor = connection.cursor()
</code></pre>
<p>Cursor is used to run SQL commands.</p>
<p>Simple meaning:</p>
<pre><code class="language-plaintext">Connection opens the database.
Cursor runs commands inside the database.
</code></pre>
<hr />
<h2>Create Table</h2>
<pre><code class="language-plaintext">cursor.execute("""
CREATE TABLE IF NOT EXISTS students (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    age INTEGER,
    marks REAL
)
""")
</code></pre>
<p>This creates a table named <code>students</code>.</p>
<p>Columns are:</p>
<pre><code class="language-plaintext">id
name
age
marks
</code></pre>
<hr />
<h2>Insert Data</h2>
<pre><code class="language-plaintext">cursor.execute("""
INSERT INTO students (name, age, marks)
VALUES (?, ?, ?)
""", ("Ram", 18, 75))
</code></pre>
<p>This adds one student into the table.</p>
<p>The <code>?</code> signs are placeholders.</p>
<p>Python safely puts values there.</p>
<hr />
<h2>Select Data</h2>
<pre><code class="language-plaintext">cursor.execute("SELECT * FROM students")
students = cursor.fetchall()
</code></pre>
<p>This selects all data from the students table.</p>
<p><code>fetchall()</code> gets all rows.</p>
<hr />
<h2>Print Data</h2>
<pre><code class="language-plaintext">for student in students:
    print(student)
</code></pre>
<p>This prints each student record.</p>
<hr />
<h1>15. Only Remember This for Database Today</h1>
<pre><code class="language-plaintext">Database stores data permanently.

SQLite creates a .db file.

Table stores data in rows and columns.

CREATE TABLE creates a table.

INSERT INTO adds data.

SELECT reads data.

Cursor runs SQL commands.
</code></pre>
<hr />
<h1>16. Final Practice</h1>
<h2>Practice 1: Dictionary</h2>
<p>Create a dictionary named <code>mobile</code>.</p>
<p>It should contain:</p>
<pre><code class="language-plaintext">brand
model
price
</code></pre>
<p>Print all details.</p>
<hr />
<h2>Practice 2: Student Management</h2>
<p>Create a student management system using dictionary.</p>
<p>It should have:</p>
<pre><code class="language-plaintext">1\. Add student
2. View student
3. Update marks
4. Check result
5. Exit
</code></pre>
<hr />
<h2>Practice 3: OOP</h2>
<p>Create a class named <code>Mobile</code>.</p>
<p>It should have:</p>
<pre><code class="language-plaintext">brand
model
price
</code></pre>
<p>Create one object and print details.</p>
<hr />
<h2>Practice 4: Database</h2>
<p>Create a database named:</p>
<pre><code class="language-plaintext">library.db
</code></pre>
<p>Create a table named:</p>
<pre><code class="language-plaintext">books
</code></pre>
<p>Columns:</p>
<pre><code class="language-plaintext">id
title
author
price
</code></pre>
<p>Then insert one book and select all books.</p>
<hr />
<h1>Final Summary</h1>
<p>Today we learned:</p>
<pre><code class="language-plaintext">Dictionary stores data in key-value pairs.

Student Management System can be made using dictionary.

OOP keeps related data and functions together.

Class is a blueprint.

Object is created from class.

SQLite is a simple database.

CREATE TABLE creates a table.

INSERT INTO adds data.

SELECT reads data from table.
</code></pre>
]]></content:encoded></item></channel></rss>