Friday, January 16, 2026

Python 36

 Python 36

Introduction to Jinja2

Jinja2 is  a template engine for python, mainly used with Flask(and also Django-like systems)

 It allows us to 

write HTML + Python logic

Display dynamic data 

Use loops, conditions variables 

Jinja2 gives (Clear,Reusable,Professional)

Browser understand only HTML, Python generate data,Jinja2 combines both.

Without Jinj2(Bad practice)

@app.route("/")

def home():

return "<h1>Welcome Naga</h1>

With Jinja2(Best practice)

@app.route("/")

def home():

return render_template("Index.html",name="naga")

<h1>welcome {{name}}</h1>

Create template with Jinja2

Connecting Flask to database and displaying records 


Examples :

Task1:

app.py

from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def home():
    return render_template('index.html', name=
                           "Subbu" , age=15)
if __name__=='__main__':
    app.run(debug=True)

templates>index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title> </head>
<body>
 
        {% if age >= 18 %}
           <h1>You are eligible to vote:{{name}} {{age}}</h1>
        {% else %}
            <h1>You are not eligible to vote:{{name}} {{age}}</h1>
        {% endif %}
       
</body>
</html>

You are not eligible to vote:Subbu 15

Task2:
List
app.py

from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def home():
    std = ["Raja", "Subbu", "Pavan","Kumar","Ajay"]
    return render_template('index.html', students=std)
if __name__=='__main__':
    app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title> </head>
<body>
       <ul>
        {% for stdind in students %}
                 <li>{{stdind}}</li>
        {% endfor %}
    </ul>
       
</body>
</html>
  • Raja
  • Subbu
  • Pavan
  • Kumar
  • Ajay
Task3: Display Table format

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>Student Name</th>
            <th>Age</th>
            <th>Marks</th>
        </tr>
        {% for name, age,mark in student_data %}
        <tr>
            <td>{{ name }}</td>
            <td>{{ age }}</td>
            <td>{{ mark }}</td>
        </tr>
        {% endfor %}
    </table>
</body>
</html>
app.py
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def home():
    std = ["Raja", "Subbu", "Pavan", "Kumar", "Ajay"]
    ag = [23, 24, 22, 25, 23]
    marks = [85, 90, 78, 88, 92]
    # Combine lists into list of tuples
    student_data = list(zip(std, ag, marks))
    return render_template('index.html', student_data=student_data)

if __name__ == '__main__':
    app.run(debug=True)


used zip function combine multiple iterables (like lists, tuples, etc.) element-wise. It creates an iterator that aggregates
elements from each of the iterables.
Output:
Student Name Age Marks
Raja 23 85
Subbu 24 90
Pavan 22 78
Kumar 25 88
Ajay 23 92


Task4: Template inheritance

base.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cloud Computing In Telugu</title>

    <link rel="stylesheet" href="{{url_for('static',filename='css/style.css') }}">
</head>

<body>

<nav >
    <ul class="menu">
        <li><a href = "/">Home</a></li>
        <li><a href="/registration">Student Registration</a></li>
        <li><a href="/courses"> Courses</a></li>
    </ul>
</nav>

    <!-- Header Section -->
    <header>
        <h1>Cloud Computing In Telugu</h1>
                  <section>
            <p>Learn how websites are built from scratch</p>
    </header>

    <!-- Main Content -->
    <main>

     {% block content %}

     {% endblock %}
    </main>

    <!-- Footer -->
    <footer>
        <p>Regards,</p>
        <p>
            <a href="https://www.cloudcomputingintelugu.com" target="_blank">
                Cloud Computing In Telugu
            </a>
        </p>
    </footer>

</body>
</html>

index.html
{% extends "base.html" %}

{% block content %}
        <!-- Introduction -->
        <section id="sec1">
            <p>
                In this training, you will learn how websites are created from scratch.
                This course is designed for beginners with no prior technical background.
            </p>

            <p>
                Web development is the process of building and maintaining websites.
                It involves designing the structure, styling the appearance, and adding interactivity.
            </p>
        </section>

        <!-- Topics Covered -->
        <section id="sec2">
            <h2>Topics Covered in This Training</h2>
            <ul>
                <li>HTML fundamentals</li>
                <li>Page structure and elements</li>
                <li>Text formatting and links</li>
                <li>Images, lists, and tables</li>
                <li>Forms and user input</li>
                <li>Introduction to CSS</li>
                <li>Basics of JavaScript</li>
                <li>Pythin full-stack development</li>
            </ul>
        </section>

        <!-- Technologies Overview -->
        <section>
            <p>
                HTML is responsible for creating the structure of a web page.
                CSS is used to make the web page look attractive.
                JavaScript adds interactivity and dynamic behavior.
            </p>
        </section>

        <!-- Outcomes -->
        <section id="sec3">
            <h2>After Completing This Training, You Will Be Able To</h2>
            <ul>
                <li>Create simple and well-structured web pages</li>
                <li>Understand and read existing website code</li>
                <li>Apply basic styling using CSS</li>
                <li>Add simple interactions using JavaScript</li>
                <li>Build a strong foundation for frontend development</li>
            </ul>
        </section>

        <!-- Audience -->
        <section id="sec4">
            <p>
                This training is suitable for students, beginners, and working professionals.
                Anyone interested in building websites or starting a career in web development can join.
            </p>
        </section>
{% endblock %}

student.html
{% extends "base.html" %}

{% block content %}
<form method="post">
        <table>
            <tr><td><label>Student Name: </label></td><td><input type ="text" name="name"></td></tr>
            <tr><td><label>Course: </label></td><td><input type ="text"  name="course"></td></tr>
           
            <tr><td><label>Email Id: </label></td><td><input type ="email"   name="email"></td></tr>
            <tr style="text-align: center;"><td colspan="2"><button type="submit">Submit</button></td></tr>
        </table>
        <h1>{{msg}}</h1>

<table>
    <tr>
        <th>Student Id</th>
        <th>Student Name</th>
        <th>Course Selected</th>
        <th>Email Id</th>
    </tr>


        {% for student in std %}
        <tr>
            <td>{{student.id}}</td>
            <td>{{student.name}}</td>
            <td>{{student.course}}</td>
            <td>{{student.email}}</td>
        </tr>
        {% endfor %}
</table>

 </form>    
{% endblock %}

index.html
{% extends "base.html" %}

{% block content %}
        <!-- Introduction -->
        <section id="sec1">
            <p>
                In this training, you will learn how websites are created from scratch.
                This course is designed for beginners with no prior technical background.
            </p>

            <p>
                Web development is the process of building and maintaining websites.
                It involves designing the structure, styling the appearance, and adding interactivity.
            </p>
        </section>

        <!-- Topics Covered -->
        <section id="sec2">
            <h2>Topics Covered in This Training</h2>
            <ul>
                <li>HTML fundamentals</li>
                <li>Page structure and elements</li>
                <li>Text formatting and links</li>
                <li>Images, lists, and tables</li>
                <li>Forms and user input</li>
                <li>Introduction to CSS</li>
                <li>Basics of JavaScript</li>
                <li>Pythin full-stack development</li>
            </ul>
        </section>

        <!-- Technologies Overview -->
        <section>
            <p>
                HTML is responsible for creating the structure of a web page.
                CSS is used to make the web page look attractive.
                JavaScript adds interactivity and dynamic behavior.
            </p>
        </section>

        <!-- Outcomes -->
        <section id="sec3">
            <h2>After Completing This Training, You Will Be Able To</h2>
            <ul>
                <li>Create simple and well-structured web pages</li>
                <li>Understand and read existing website code</li>
                <li>Apply basic styling using CSS</li>
                <li>Add simple interactions using JavaScript</li>
                <li>Build a strong foundation for frontend development</li>
            </ul>
        </section>

        <!-- Audience -->
        <section id="sec4">
            <p>
                This training is suitable for students, beginners, and working professionals.
                Anyone interested in building websites or starting a career in web development can join.
            </p>
        </section>
{% endblock %}

static>css>style.css
   body{
        font-family: Arial, sans-serif;
        line-height: 1.6;
        background-color: #f4f6f8;
        margin:0;
        padding: 20px;
    }

    main{
        width:80%;
        margin:30px;
        padding: 25px;
        background-color: white;
        border-radius: 6px;

    }
    header{
        background-color: #2c3e50;
        color: white;
        padding:20px;
        text-align:center;
    }

    section{

        margin-bottom:25px

    }

    h2{
        color:#2c3e50;
        border-bottom: 2px solid #ddd ;
        padding-bottom: 5px;
    }

    ul{
        margin-left: 20px;

    }

    footer{
        text-align: center;
        padding: 15px;
        background-color: #2c3e50;
        color:white

    }
    footer a{
        color: #ffd700;
        text-decoration: none;
    }



 /* Menu bar */

 nav{
    background-color: #2c3e50;
 }

.menu{
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
 }

.menu li{
    margin: 0;
 }

.menu li a{

    display: block;
    padding: 14px 20px;
    color: white;
    text-decoration: none;
    font-weight: bold;

 }

.menu li a{

    display: block;
    padding: 14px 20px;
    color: white;
    text-decoration: none;
    font-weight: bold;

 }

.menu li a:hover{
    background-color: #1a252f;
 }

button {
    height: 50px;
    width: 250px;
    padding: 10px 20px;
    margin: 8px;

    background-color: #2563eb;   /* Blue */
    color: white;

    border: none;
    border-radius: 8px;

    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: 500;

    cursor: pointer;
    transition: all 0.3s ease;
}
        table {
            border-collapse: collapse;
            width: 70%;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: center;
        }
        th {
            background-color: #f2f2f2;
        }

app.py
# pip install pymysql

from flask import Flask,render_template, request

app=Flask(__name__)
@app.route("/")
def home():
    return render_template("index.html")

@app.route("/registration",methods=["GET", "POST"])
def student():
    return render_template("student.html")

@app.route("/courses")
def courses():
    return render_template("courses.html")


if __name__=="__main__":
    app.run(debug=True)

courses.html

{% extends "base.html" %}

{% block content %}
<form>
<ul>
    <li>AWS</li>
    <li>Azure</li>
    <li>GCP</li>
    <li>DevOps</li>
</ul>
 </form>    
</body>
</html>
{% endblock %}



Output



Task 5:
Get and Post student details using database
Install: pip install pymysql for db connection

app.py
# pip install pymysql

from flask import Flask,render_template, request
import pymysql

def dbconnection():
    conn=pymysql.connect(host="Localhost",user="ccitsource",password="SourcePassword123!",database="ccitdbsource")
    return conn

app=Flask(__name__)
@app.route("/")

def home():
    return render_template("index.html")

@app.route("/registration",methods=["GET", "POST"])
def student():
    message="Get method called"
    if  request.method=="POST":
        name=request.form.get("name")
        course=request.form.get("course")
        email=request.form.get("email")
        message="Post method called"

        conn=dbconnection()
        cursor=conn.cursor()
        sql="insert into student(std_name,course,email_id) values(%s,%s,%s)"
        cursor.execute(sql,(name,course,email))
        conn.commit()
        cursor.close()
        conn.close()
        message="Student Registered Successfully"
    # GET the student details
    conn=dbconnection()
    cursor=conn.cursor(pymysql.cursors.DictCursor)
    sql="select std_name,course,email_id from student"
    cursor.execute(sql)
    student=cursor.fetchall()
    cursor.close()
    conn.close()

    return render_template("student.html", msg=message, std=student)

@app.route("/courses")
def courses():
    return render_template("courses.html")

if __name__=="__main__":
    app.run(debug=True)

index.html
--Same as above task4
base.html
--Same as above task4
style.css
--Same as above task4
student.html
{% extends "base.html" %}

{% block content %}
<form method="post">
        <table>
            <tr><td><label>Student Name: </label></td><td><input type ="text" name="name"></td></tr>
            <tr><td><label>Course: </label></td><td><input type ="text"  name="course"></td></tr>
            <tr><td><label>Email Id: </label></td><td><input type ="email"   name="email"></td></tr>
            <tr style="text-align: center;"><td colspan="2"><button type="submit">Submit</button></td></tr>
        </table>
        <h1>{{msg}}</h1>

        <table>
            <tr>
                <th>Student Name</th>
                <th>Course Selected</th>
                <th>Email Id</th>
            </tr>
                {% for student in std %}
                <tr>
                    <td>{{student.std_name}}</td>
                    <td>{{student.course}}</td>
                    <td>{{student.email_id}}</td>
                </tr>
                {% endfor %}
</table>

 </form>    
{% endblock %}

Mysql:
create table ccitdbsource.student( std_name varchar(100), mobile decimal(20), course varchar(100), email_id varchar(100));

Ouput:


Task6: Delete


Student.html

{% extends "base.html" %}

{% block content %}
<form method="post" action="/registration">
        <table>
            <tr><td><label>Student Name: </label></td><td><input type ="text" name="name"></td></tr>
            <tr><td><label>Course: </label></td><td><input type ="text"  name="course"></td></tr>
            <tr><td><label>Email Id: </label></td><td><input type ="email"   name="email"></td></tr>
            <tr style="text-align: center;"><td colspan="2"><button type="submit">Submit</button></td></tr>
        </table>
        {% if msg %}
             <h3 style="color: green;">{{ msg }}</h3>
        {% endif %}
</form>
        <table>
            <tr>
                <th>Student Name</th>
                <th>Course Selected</th>
                <th>Email Id</th>
                <th>Action</th>
            </tr>
                {% for student1 in std %}
                <tr>
                    <td>{{student1.std_name}}</td>
                    <td>{{student1.course}}</td>
                    <td>{{student1.email_id}}</td>
                    <td style="text-align:center;">
                        <form method="post" action="{{ url_for('delete_student', std_name=student1.std_name) }}">
                        <button type="delete"
                        onclick="return confirm('Are you sure you want to delete this student?')">
                        Delete
                </button>

            </form>
        </td>
                </tr>

                {% endfor %}
</table>

 </form>    
{% endblock %}

--Thanks
app.py
# pip install pymysql
from flask import Flask,render_template, request,url_for,redirect
import pymysql

app=Flask(__name__)
def dbconnection():
    conn=pymysql.connect(host="Localhost",user="ccitsource",password="SourcePassword123!",database="ccitdbsource")
    return conn

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/registration",methods=["GET", "POST"])
def student():
    message="All Students records"
    if  request.method=="POST":
        name=request.form.get("name")
        course=request.form.get("course")
        email=request.form.get("email")
        message="post method called"
       
        if name and course and email:
            conn = dbconnection()
            cursor = conn.cursor()
            sql = "INSERT INTO student (std_name, course, email_id) VALUES (%s, %s, %s)"
            cursor.execute(sql, (name, course, email))
            conn.commit()
            cursor.close()
            conn.close()
        else:
            message = "All Students records"

    # GET the student details
    conn=dbconnection()
    cursor=conn.cursor(pymysql.cursors.DictCursor)
    sql="select std_name,course,email_id from student"
    cursor.execute(sql)
    student=cursor.fetchall()
    cursor.close()
    conn.close()

    return render_template("student.html", msg=message, std=student)

@app.route("/delete_student/<string:std_name>", methods=["POST"])

def delete_student(std_name):
    conn=dbconnection()
    cursor=conn.cursor()
    sql="delete from student where std_name=%s"
    cursor.execute(sql,(std_name,))

    conn.commit()
    cursor.close()
    conn.close()
    return redirect(url_for("student"))

@app.route("/courses")
def courses():
    return render_template("courses.html")

if __name__=="__main__":
    app.run(debug=True)

remaining Same as above
base.html
style.css
index.html

Output:

-thanks..



Monday, January 12, 2026

Python 35

 Python 35

Web Development with Flask 

What is web-browser? (Chrome/edge/Firefox)

How a Web browser works 

User --> browser-->Web server--> Browser-->User 

A Web Browser can : 

Send HTTP requests(GET,POST)

Receive responses from servers 

Render HTML and apply CSS Styles

Java Script

Display Images ,videos ,text

What is web-server? (Apache/NGNX/IIS/Gunicorn/Tomcat)

A Web server is a software(and sometime hardware) that requests from a browser and send responses back(HTML,JSON,Images,etc.)

It has completed setup, which page to go all software code will be exists

Browser -->request -->webserver (routing)-->response-->Browser)

Web servers (selected List)  

   Web server                       Plant/Language     Used For 

1. Apach HTTP server -->   Cross-plantform  static & dynamic websites

2. Nginx                                 Cross-platform       High-traffic websites

3. Microsoft IIS                     Windows                 .Net web applications

4. Gunicorn                            Python                    Flask/Django production apps

5.Apache tomcat                   Java                         Java Web applications

Introduction to Flask 

 It is web framework it will take request from webserver and send response to browser. light weight frame work ,high weight django

-->Flask is a lightweight web framework written in python

-->It helps developer build web applications and APIS easily

It simple words:

 Flask helps Python programs talk to the browser.

 pip install flask

Why do we need flask?

 If you want to print a message using python, there are multiple ways.

1.Print in the terminal.

  def index():

 print("Welcome to ccit")

2.Print in the web-page 

  def index():

    return "Welcome to ccit"

Setting Up a Flask Project  

Task1:

app.py:

from flask import Flask
"""
Create a Flask application instance.
__name__ is a special Python variable that gets the name of the current module.
When the script is run directly, __name__ equals "__main__".
"""
app = Flask(__name__)
"""
Define a route for the root URL ('/').
The @app.route decorator tells Flask what URL should trigger this function.
'GET' method is the default, so methods=['GET'] is optional.
"""
@app.route('/')
def home():
    """Handle requests to the root URL and return a welcome message."""
    return "Welcome to the Flask Web Application!"
"""
Check if this script is executed directly (not imported as a module).
If so, run the Flask development server with debug mode enabled.
"""
if __name__ == '__main__':
    # Debug mode provides auto-reload and detailed error pages
    app.run(debug=True, port=5000)

 * Running on http://127.0.0.1:5000

Display test in web page :

Welcome to the Flask Web Application!

Task2: Render template

  • render_template → used to display an HTML file This allows Flask to show web pages, not just plain text.

app.py

from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
    return render_template("index.html")
if __name__ == '__main__':
    app.run(debug=True, port=5000)

Index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cloud Computing In Telugu</title>
    <link rel="stylesheet" href="static/style.css">
</head>
<body>
<nav >
    <ul class="menu">
        <li><a href = "/">Home</a></li>
        <li><a href="/send">Send</a></li>
        <li><a href="/Student">Student</a></li>
    </ul>
</nav>
    <!-- Header Section -->
    <header>
    <h1>AWS Cloud Computing</h1>
    <section>
              <p>Learn how websites are built from scratch</p>
    </header>

    <main>
        <section id="sec4">
            <p>
                This training is suitable for students, beginners, and working professionals.
                Anyone interested in building websites or starting a career in web development can join.
            </p>
        </section>

    </main>

    <!-- Footer -->
    <footer>
        <p>Regards,</p>
        <p>
            <a href="https://www.Google.com" target="_blank">
                Google Page
            </a>
        </p>
    </footer>

</body>
</html>

Web page Output:

Above one example default method Get 

Task3: 

We have different type of method in routing get/put/post/delete

While click any button and expecting response is called post method 

app.py

from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def home():
    return render_template('index.html', title="Home Page")
@app.route('/', methods=['POST'])  
def send():
    topics = """
    <h2>Topics Covered in This Training</h2>
    <ul>
        <li>Introduction to Cloud Computing</li>
        <li>AWS Services Overview</li>
        <li>Deploying Applications on AWS</li>
        <li>Managing AWS Resources</li>
        <li>Security Best Practices</li>
    </ul>
    """
    return render_template('index.html', title="Home Page", msg=topics)

if __name__ == '__main__':
    app.run(debug=True)

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cloud Computing In Telugu</title>
    <link rel="stylesheet" href="static/style.css">
</head>
<body>
<nav >
    <ul class="menu">
        <li><a href = "/">Home</a></li>
        <li><a href="/send">Send</a></li>
        <li><a href="/Student">Student</a></li>
    </ul>
</nav>
    <!-- Header Section -->
    <header>
    <h1>AWS Cloud Computing</h1>
    <section>
              <p>Learn how websites are built from scratch</p>
    </header>
    <main>
 
        <section id="sec4">
            <form method="post" >
            <button type="submit">Enroll Now</button>
            {% if msg %}
                {{ msg|safe }}
            {% endif %}
        </form>

            <h2>Join Our Cloud Computing Course Today!</h2>
         </section>
    </main>
    <!-- Footer -->
    <footer>
        <p>Regards,</p>
        <p>
            <a href="https://www.Google.com" target="_blank">
                Google Page
            </a>
        </p>
    </footer>
</body>
</html>

When click button request send to Post metod ,display below text


Web development basics:

We need  to create an object of the flask class(app=Flask(_name_)

 A route(@app.route("/")) guides the Flash framework to execute a particular python function when a specific URL is accessed 

(If _name_ =="_main_":)This block ensures that the Flask application runs only when the file is executed directly, not when it is imported 

(app.run(debug=true))starts the Flask development server 


Handling Routes:

Routing navigation the one page to another 

Routing maps URLs to specific functions (views) in your application. When a user visits a URL, Flask calls the corresponding function to handle that request.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cloud Computing In Telugu</title>
    <link rel="stylesheet" href="static/style.css">
</head>
<body>
<nav >
    <ul class="menu">
        <li><a href = "/">Home</a></li>
        <li><a href="/send1">Send</a></li>
        <li><a href="/student">Student</a></li>
    </ul>
</nav>
    <!-- Header Section -->
    <header>
    <h1>AWS Cloud Computing</h1>
    <section>
              <p>Learn how websites are built from scratch</p>
    </header>
    <main>
 
        <section id="sec4">
            <form method="post" >
            <button type="submit">Enroll Now</button>
            {% if msg %}
                {{ msg|safe }}
            {% endif %}
        </form>

            <h2>Join Our Cloud Computing Course Today!</h2>
         </section>
    </main>
    <!-- Footer -->
    <footer>
        <p>Regards,</p>
        <p>
            <a href="https://www.Google.com" target="_blank">
                Google Page
            </a>
        </p>
    </footer>
</body>
</html>

app.py 

from flask import Flask,render_template

app = Flask(__name__)
@app.route('/')
def home():
    return render_template('index.html', title="Home Page")
@app.route('/send1')
def send1():
    return "Thank you for enrolling!"

@app.route('/student')
def student():
    return "Thank you for student enrolling!"

@app.route('/', methods=['POST'])  
def send():
    topics = """
    <h2>Topics Covered in This Training</h2>
    <ul>
        <li>Introduction to Cloud Computing</li>
        <li>AWS Services Overview</li>
        <li>Deploying Applications on AWS</li>
        <li>Managing AWS Resources</li>
        <li>Security Best Practices</li>
    </ul>
    """
    return render_template('index.html', title="Home Page", msg=topics)

if __name__ == '__main__':
    app.run(debug=True)

When click Send 


It will call send tab it called send1 function 

Same way when click student tab it will call student function 



--Thanks 





Saturday, December 6, 2025

Python Day17

Python Day17

Remove Duplicate using Inheritance :

Duplicate removal in OOP means moving the common(repeated) code into a centralized place(usually a parent class).So that multiple classes can reuse it without rewriting.

Problem with duplicate code                 Solution using inheritance 

Code repeated again and again             Write one -->reuse every where

Hard to update later                               Update only in parent class 

More bugs                                                Less complexity


How inheritance help ?

Common code(name ,age show method) --> in parent class.

unique code in child classes only.

it increase the readability and reusability 

See below repeated twice:

class Student:
    def __init__(self, username: str, age: int, sfee: str):
        self.username = username
        self.age = age
        self.sfee = sfee
        print(self.username, "Student created.", self.age, self.sfee)

std = Student("john_doe", 20, "Paid")

class Faculty:
    def __init__(self, username: str, age: int, sfee: str):
        self.username = username
        self.age = age
        self.sfee = sfee
        print(self.username, "Faculty created.", self.age, self.sfee)
fac = Faculty("dr_smith", 45, "Unpaid")    


See Below code Parent class Comm

class AdminClass:
    def __init__(self, username: str, age: int, sfee: str):
        self.username = username
        self.age = age
        self.sfee = sfee
        print(self.username, "Admin created.", self.age, self.sfee)

class Student(AdminClass):
    def __init__(self, susername: str, sage: int, sfee: str):
        AdminClass.__init__(self, susername, sage, sfee)
        print(self.username, "Student created.", self.age, self.sfee)

class Faculty(AdminClass):
    def __init__(self, fusername: str, fage: int, sfee: str):
        AdminClass.__init__(self, fusername, fage, sfee)
        print(self.username, "Faculty created.", self.age, self.sfee)

std = Student("john_doe", 20, "Paid")
fac = Faculty("dr_smith", 45, "Unpaid")




See Below code Parent class Comm


See Below code Parent class Comm

Saturday, November 29, 2025

Python Day

Python Day1 :3-Nov-2025

Python Full stack Developer

What is full stack developer do?

A Full stack Developer   is a software Professional who can build both the front end and backend parts of a web application.

Full-Stack Developer = Front-end + Backend database + Deployment

1.Front-end(Client side)

This is the part users interact with the website's look and feel.

Skill & technologies:

HTML -->Structure of web pages

CSS-->Staying and layout 

Java Script -> Interactivity

Framework/Libraries -->React,Angular,Jquery,etc.

2.Back-End(server side)

This is the brain of the application -where logic,database,and processing happen.

Skills & technologies:

Programming Languages-->Python, java, C# Nodes.js

Frameworks -->Django,Flask,Sprint Boot,ASP.NET

Databases-->Mysq,Postgressql,MongoDB

APIs-->Restful

Road map to Become a Full-stack Python Developer

1.ProgrammingLanguage (Python,C,C++,C#,Java,Ruby,NodeJS,etc..

2.Scripting/Front-end Languages(JavaScript,jQuery,HTML,Style Sheets,etc

3.Database Knowledge(Mysql,Sql server,Orace,Nosql(MongolDB,DynamoDB)etc)

4.Web framework/Techonologies(Django,Flask,ASP.Net,MVC,Spring Boot,etc)

5.Version Control/repositories(Git/Github,Bitbucket,..etc)

6.Operating System(Linux base os(Ubuntu,Amazon Linux),window,Macos,etc)

Python Day2:4-Nov-2025

What is a programming Language?

A programming Language is a type of compute language specifically designed to write programs -sets of instructions that a computer can execute to perform specific tasks.

Ex: Python, C#, C++, Java, JavaScript,etc

Purpose:To develop application ,To control hardware and software behavior, To solve computational problems.

Type of Programming Languages 

Programming languages can be broadly divided into three main types:

1)Low-level languages: These are close to machine language(binary or assembly),not understand to human

Ex: Assembly Language, Machine code.

2)High-level languages: Easier for human to read and write ,They use English like word 

Ex:- Python,Java,C#,C++,Java Script

3)Scripting languages: A type of high-level language mainly used for automation,web development, and processing

Ex:-Python,Java Script,Perl,Ruby,PHP

Introduction to Python  -History of Python 

Created by Guido van Rossum

Year :1989(released in 1991)

Origin: Developed in the Netherlands at CWI(Centrum Wiskunde & informatica)

Named after: "Monty Python's Flying circus", a British Comedy show --not the snake! 

Design goal: To make programming simple ,readable , and fun

Python version:

Python 1.0 -->Released in 1991

Python 2.0 -->Released in 2000(added Unicode support)

Python 3.0 -->Released in 2008(modern version, still used today)

Current version 3.14 https://www.python.org/

Importance of Python

Python is one of the most popular and versatile programming languages today.

Easy to Learn: Simple syntax,like english 

Versatile: Used for web, AI data science automation

Open source: Free to use and modify

Cross-platform: Runs on windows, Mac, Linux

Huge community: Millions of developers and libraries.

Powerful libraries: NumPy, Pandas, Django, TensorFlow, Flask, etc

What can I Build Using Python ?

Web Development --> Django,Flask,Websites 

Data Science -->Data analysis , Visualization

Artificial Intelligence --> Chatbots,Voice Assistants 

Machine learning --> Predictive models,r recommendation systems

Game development -->2D/3D games Using Pygame

Desktop application -->GUI tools(Tkinter,PyQt)

Automation --> File renaming,email sending,web scraping 

Cybersecurity -->Network scanners, password managers

Internet of things(IOT) -->Smart home systems 

Installation 

Step1: Download latest version https://www.python.org/downloads/

Check both these option 

  • Use admin privileges when installing py.exe
  • Add python.exe to PATH

Click Install Now

C:\Users\Administrator>python --version

Python 3.14.0

IDE environment for Python

An IDE is  a software application that provides everything     

What PyCharm?

PyCharm is an IDE (Integrated Development Environment) used for writing ,running and debugging python programs efficiently.

It's one of the most popular tools for Python developers, created by  a company called Jetbrains

Download 

https://www.jetbrains.com/pycharm/download/?section=windows

VS Code ?

Visual studio code is free ,open-source editor developed by microsoft ,Most popular tool used by developer worldwide ,including Python programmer to write,run  and debug code.

https://code.visualstudio.com/download

Python Day3:5-Nov-2025

Installation PyCharm 

Installation VS Code 

Python Day4:6-Nov-2025

Python syntax and structure:

  • Syntax mean the set of rules that define how code must be written so python can understand it.
  • Python's syntax is designed to be clean, readable , and simple  -- it uses indentation(spaces) instead of braces {} . 
  • code runs top to button, directly 

For ex:

It will treated as String 

val1 = input("Enter first value: ")
val2 = input("Enter second value:")
print("You entered:", val1 + val2)

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python syntax.py

Enter first value: 20

Enter second value:26

You entered: 2026

Type casting:

val1 = int(input("Enter first value: "))
val2 = int(input("Enter second value:"))
print("You entered:", val1 + val2)

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python syntax.py

Enter first value: 20

Enter second value:26

You entered: 46

IF condition :

val1 = int(input("Enter first value: "))
val2 = int(input("Enter second value:"))
if val1 > 100:
    print("First Value exceeds 100.")

if val2 > 200:
    print("Second Value exceeds 200.")

print("Sum of the above values entered:", val1 + val2)

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python syntax.py

Enter first value: 200

Enter second value:300

First Value exceeds 100.

Second Value exceeds 200.

Sum of the above values entered: 500

Method 
name = input("Enter your name: ")
def greet_user():
    print("Hello, " + name + "! Welcome to the program.")
    return "Greeting sent."

greet_user()        

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python syntax.py

Enter your name: Subrahmanyam

Hello, Subrahmanyam! Welcome to the program.

This f means formatted string display the value between string

print(f"Hello,{name}, Welcome to the program.")

  • Comments 
Single line Comments 
# This is the Single line 
Muti-line Comments : Use Triple quotes """ """ or     ''' '''

""" Calling the function to greet the user """
''' Calling the function to greet the user '''
greet_user()    

  • Function Documentation (Doc String)

Every function can have its own docstring to describe what it does

Single Doc string

def add(a,b):
    """ This function adds two numbers and returns the result """
    return a + b
print(add.__doc__)

Multiple doc string

def add(a,b):
    """ This function adds two numbers and returns the result
     Second function adds two numbers and returns the result1 """
    return a + b
print(add.__doc__)

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python method.py

This function adds two numbers and returns the result 

Second function adds two numbers and returns the result1

  • Code Errors and Debugging Basics 
Type of Errors :
Syntax error : Invalid code format 
For example: Print("Hello" missing)
Runtime Error :Error while program runs
For example: 10/0 -->ZeroDivisionError
Logical Error: No crash, but wrong output
For example: Using + instead of * 

Example Debugging:

a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
def add(a, b):
    return a / b
print(add(a, b))    

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python method.py  
File "C:\Users\Administrator\Desktop\CCIT\PythonCourse\method.py", line 4, in add
    return a / b
           ~~^~~
ZeroDivisionError: division by zero
PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> 

Fixed Version:
Try catch block
try:
    a = int(input("Enter the first number: "))
    b = int(input("Enter the second number: "))
    def add(a, b):
        return a / b
    print(add(a, b))  
except ZeroDivisionError:
        print("Error: Division by zero is not allowed.")

PS C:\Users\Administrator\Desktop\CCIT\PythonCourse> python method.py
Enter the first number: 20
Enter the second number: 0
Error: Division by zero is not allowed.

  • Python Style Guide (PEP 8) Overview 
What is PEP 8?
PEP 8 stands for Python Enhancement Proposal #8 
It is the official style guide for writing Python code.
In simple words:
PEP 8 is like a rulebook that helps you write python code that looks clean, consistent, and professional 
1.Indentation ,2 Maximum line length,3.Blank Lines (separate section of the code),
4. Space around operators and commas (Always one space = ,+..etc)
5. Naming Conversation
 Type 
Variable/Functions :lowercase_with_underscores 
 For example: student_name, get_data()
 Constants: ALL_CAPS
 For example: P1=3.14,MAX_SPEED = 100
 Classes :PascalCase
 For example: class StudentDetails:
 Private variables: Start with_
 For example: _temp_value 
 Modules: Short,lowercase names 
 For example: math_utils.py
6. Function and class Definitions 
 Leave two blank lines before defining a new function or class 
7.Comments 

Navigating Python's Interactive shell

What is the Python Interactive shell?
The Python interactive shell (also known as the REPL) is a command line environment that lets you type and execute python commands one at a time -- and see the result immediately.
"REPL" Stands for 
 Read-->Eval-->print-->Loop
It read your command evaluates it, print the result and loops back for the next command 
It's like a python playground -where you can test small code snippets instantly without writing or saving a .py file 

--Thanks