<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://chezhian0599.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://chezhian0599.github.io/" rel="alternate" type="text/html" /><updated>2025-10-19T15:31:46+00:00</updated><id>https://chezhian0599.github.io/feed.xml</id><title type="html">Elanchezhian’s TILs</title><subtitle>Let&apos;s make it simple</subtitle><author><name>Elanchezhian K R</name></author><entry><title type="html">Learning Python</title><link href="https://chezhian0599.github.io/2025/09/21/learning-python.html" rel="alternate" type="text/html" title="Learning Python" /><published>2025-09-21T00:00:00+00:00</published><updated>2025-09-21T00:00:00+00:00</updated><id>https://chezhian0599.github.io/2025/09/21/learning-python</id><content type="html" xml:base="https://chezhian0599.github.io/2025/09/21/learning-python.html"><![CDATA[<hr />

<h1 id="learning-python-fundamentals">Learning Python Fundamentals</h1>

<p><em>(Inspired by Bro Code Tutorials)</em></p>

<h2 id="augmented-assignment-operators">Augmented Assignment Operators</h2>

<p>Python supports augmented assignment operators, which help simplify code for updating variable values.
For example:</p>

<pre><code class="language-python">friends = 0
friends += 1
</code></pre>

<p>Here, <code>+=</code> is the augmented assignment operator.
This is equivalent to:</p>

<pre><code class="language-python">friends = friends + 1
</code></pre>

<p>These operators help write cleaner and more concise code.</p>

<hr />

<h2 id="program-compute-circumference--area-of-a-circle">Program: Compute Circumference \&amp; Area of a Circle</h2>

<p>This program calculates the circumference and area for a given radius:</p>

<pre><code class="language-python">import math

radius = float(input("Enter the radius of a circle: "))

circumference = 2 * math.pi * radius
area = math.pi * pow(radius, 2)

print(f"Circumference of circle is {round(circumference, 2)} cm")
print(f"Area of circle is {round(area, 2)} cm^2")
</code></pre>

<hr />

<h2 id="program-calculate-hypotenuse-of-a-right-triangle">Program: Calculate Hypotenuse of a Right Triangle</h2>

<p>Use the Pythagorean theorem to find the hypotenuse:</p>

<pre><code class="language-python">import math

a = float(input("Enter the length of side A: "))
b = float(input("Enter the length of side B: "))

c = math.sqrt(pow(a, 2) + pow(b, 2))
print(f"Length of side C is {c}")
</code></pre>

<hr />

<h2 id="simple-calculator-app-----">Simple Calculator App (+, -, *, /)</h2>

<p>A basic calculator allowing user-chosen operations:</p>

<pre><code class="language-python">operator = input("Enter the operator (+, -, *, /): ")

num1 = float(input("Enter the 1st number: "))
num2 = float(input("Enter the 2nd number: "))

if operator in ("+", "-", "*", "/"):
    if operator == "+":
        result = num1 + num2
    elif operator == "-":
        result = num1 - num2
    elif operator == "*":
        result = num1 * num2
    elif operator == "/":
        result = num1 / num2
    print(result)
else:
    print(f"{operator} is not a valid operator")
</code></pre>

<hr />

<h2 id="weight-converter-kilograms--pounds">Weight Converter: Kilograms ↔ Pounds</h2>

<p>Convert between kilograms and pounds:</p>

<pre><code class="language-python">weight = float(input("Enter the weight: "))
unit = input("Kilogram or Pounds (K or L)? ")

if unit == "K":
    result = weight * 2.20
    print(f"{weight} Kg is equal to {result} Lbs")
elif unit == "L":
    result = weight / 2.20
    print(f"{weight} Lbs is equal to {result} Kg")
else:
    print(f"{unit} is not a valid unit")
</code></pre>

<hr />

<h2 id="conditional-expressions-ternary-operator">Conditional Expressions (Ternary Operator)</h2>

<p>Python allows concise conditional assignments and print statements using one-line if-else:</p>

<pre><code class="language-python"># Example 1
num = 0
print('Positive' if num &gt; 0 else 'Negative')

# Example 2
even_or_odd = 4
print('Even' if even_or_odd % 2 == 0 else 'Odd')

# Example 3
user_role = 'Guest'
print('Full Access' if user_role == 'Admin' else 'Limited Access')

# Example 4
a = 7
b = 9
print(a if a &gt; b else b)  # Max
print(a if a &lt; b else b)  # Min
</code></pre>

<p>Pattern: <code>x if condition else y</code></p>

<hr />

<h2 id="username-validator-exercise">Username Validator Exercise</h2>

<p>Check if a username meets specific conditions:</p>

<ul>
  <li>Maximum 12 characters</li>
  <li>Only alphabetic letters</li>
  <li>No spaces or numbers</li>
</ul>

<pre><code class="language-python">def username_validator(username):
    if len(username) &gt; 12:
        return "Total characters should not be more than 12"
    elif not username.isalpha():
        return "Your username cannot contain numbers"
    elif " " in username:
        return "Your username cannot contain spaces"
    else:
        return f"Welcome {username} !!"
</code></pre>

<hr />

<h2 id="while-loop-example-user-input-validation">While Loop Example: User Input Validation</h2>

<p>While loops execute code until a condition is no longer met:</p>

<pre><code class="language-python">num = int(input("Enter a number between 1 and 10: "))

while num &lt; 1 or num &gt; 10:
    print("The entry is not valid")
    num = int(input("Enter a number between 1 and 10: "))

print(f"{num} is a valid number")
</code></pre>

<hr />

<h2 id="compound-interest-calculator-two-approaches">Compound Interest Calculator (Two Approaches)</h2>

<p><strong>Approach 1: Using Sequential While Loops</strong></p>

<pre><code class="language-python">principal = 0
years = 0
interest = 0

while principal &lt;= 0:
    print("Principal should be greater than 0")
    principal = int(input("Enter the principal (&gt; 0): "))

while years &lt;= 0:
    print("Years should be greater than 0")
    years = int(input("Enter the years (&gt; 0): "))

while interest &lt;= 0:
    print("Interest should be greater than 0")
    interest = int(input("Enter the interest (&gt; 0): "))

total = principal * pow((1 + interest/100), years)
print(f"Balance after {years} year(s): ${total:.2f}")
</code></pre>

<p><strong>Approach 2: Using Infinite While Loops (<code>while True</code>)</strong></p>

<pre><code class="language-python">while True:
    principal = int(input("Enter the principal (&gt; 0): "))
    if principal &gt; 0:
        break
    print("Principal cannot be less than 0")

while True:
    years = int(input("Enter the years (&gt; 0): "))
    if years &gt; 0:
        break
    print("Years cannot be less than 0")

while True:
    interest = int(input("Enter the interest (&gt; 0): "))
    if interest &gt; 0:
        break
    print("Interest should be greater than 0")

total = principal * pow((1 + interest/100), years)
print(f"Balance after {years} year(s): ${total:.2f}")
</code></pre>

<hr />

<h2 id="key-loop-concepts">Key Loop Concepts</h2>

<ul>
  <li><strong>Continue:</strong>
Skips the current iteration if a certain condition is met.</li>
  <li><strong>Break:</strong>
Immediately exits the loop if a certain condition is met.</li>
</ul>

<hr />

<h2 id="building-a-count-down-timer">Building a count-down timer</h2>
<pre><code>import time

my_time = int(input("Enter the time in seconds: "))

for x in range(my_time,0,-1):
    seconds = x%60
    minutes = int(x/60)%60
    hours = int(x/3600)
    print(f"{hours:02}:{minutes:02}:{seconds:02}")
    time.sleep(1)
print("TIME'S UP!!")

</code></pre>

<h2 id="nested-loops">nested loops</h2>

<ul>
  <li>Here is the <strong>nested loops</strong> in python, nested loop is loop within the loop</li>
  <li>To understand this concept more clearly we demontrated it with logic below that gets the number of Row, columns to display the rectangle</li>
</ul>

<pre><code>rows = int(input('Enter number of rows: '))
columns = int(input('Enter number of columns: '))
symbol = input('Enter the symbol: ')


for i in range(rows):
    for j in range(columns):
        print(symbol, end = '')
    print()
</code></pre>
<p>This collection provides clean code snippets and essential Python logic fundamentals, ideal for beginners and anyone reviewing core concepts.</p>]]></content><author><name>Elanchezhian K R</name></author><category term="Other" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Python Interpreter</title><link href="https://chezhian0599.github.io/2025/09/20/python-interpreter.html" rel="alternate" type="text/html" title="Python Interpreter" /><published>2025-09-20T00:00:00+00:00</published><updated>2025-09-20T00:00:00+00:00</updated><id>https://chezhian0599.github.io/2025/09/20/python-interpreter</id><content type="html" xml:base="https://chezhian0599.github.io/2025/09/20/python-interpreter.html"><![CDATA[<h2 id="what-is-a-python-interpreter">What is a Python Interpreter</h2>

<p>A Python interpreter is software that reads and executes Python code. When a programmer writes source code in Python, the interpreter compiles it into bytecode <strong>(a lower-level, platform-independent representation)</strong>. This bytecode is then executed by the <strong>Python Virtual Machine (PVM)</strong>, which further interacts with the underlying machine code executed by the CPU.</p>

<h2 id="why-python-is-called-an-interpreted-language">Why Python is called an Interpreted Language</h2>

<p>Python is called an <strong>interpreted language</strong> because the source code is not directly compiled into machine code beforehand. Instead, the Python interpreter processes the code, compiles it into bytecode, and executes it line by line using the Python Virtual Machine during runtime.</p>]]></content><author><name>Elanchezhian K R</name></author><category term="Other" /><summary type="html"><![CDATA[What is a Python Interpreter]]></summary></entry></feed>