Posts

Showing posts with the label Youtube

World Fibonacci Day! Mastering the Fibonacci Sequence in Python Line

How a classic math pattern powers clean Python logic Although people often associate technical interviews with difficult whiteboards problems and advanced algorithm knowledge, one of the best known computer science problems is that of generating numbers in the Fibonacci sequence something that can be elegantly achieved in Python. Today as we are celebrating World Fibonacci Day on the day of 23rd November, in anticipation of a future technical interview or to refresh your core Python knowledge, it is highly beneficial to understand how to iteratively generate the Fibonacci sequence. Compared to a (inefficient) recursive solution, an iterative while loop is both memory efficient and easy to comprehend. Understanding the Mathematical Pattern The Fibonacci sequence is generated by continuously summing the previous two numbers in the following manner (starting from 0 and 1): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... Mathematically, this is represented by the equation F(...

How to Find LCM of Two Numbers in Python

The Math Behind LCM (Prime Factorization) Lets see how Least Common Multiple (LCM) works on paper. Every whole number greater than 1 can be broken down into a unique combination of prime numbers, a rule mathematicians call the Fundamental Theorem of Arithmetic . When you compare two numbers, their LCM is simply the smallest number that contains all the prime factors from both inputs. Let's take 15 and 10 as an example Factors of 15: 3 × 5 Factors of 10: 2 × 5 To build the LCM, we take the highest count of each prime factor that appears in either number: one 2 , one 3 , and one 5 . Multiply those together (2 × 3 × 5), and you get 30  the smallest positive number that both 15 and 10 divide into cleanly without leaving a remainder. Doing this with a pen and paper is straightforward for small numbers, but teaching a computer to factor massive 20-digit numbers takes far too much processing time. That is why programmers rely on remainder loops or GCD shor...

How to Find HCF (GCD) of Two Numbers in Python

The Math Behind HCF (Prime Factorization) Before running a loop in Python, it helps to look at how HCF works on paper. Every whole number greater than 1 can be split into a unique set of prime numbers, a rule mathematicians call the Fundamental Theorem of Arithmetic . When you compare two numbers, their HCF is just the product of the prime factors they both have in common. Take 64 and 36 as an example: Factors of 64: 2 × 2 × 2 × 2 × 2 × 2 (2 6 ) Factors of 36: 2 × 2 × 3 × 3 (2 2 × 3 2 ) Both numbers share the prime factor 2 . Since 36 only has two 2s while 64 has six, we take the smaller overlap: 2 × 2 = 4 . Doing this with a pencil is easy for small numbers, but teaching a computer to factor 20-digit numbers takes way too much processing power. That is why programmers rely on remainder loops instead of prime factorization. HCF vs. LCM: How They Connect If you are preparing for coding interviews, you will rarely see HCF come up without its twin: the Least Commo...

How to Check If a Number Is Prime in Python

In mathematics, a prime number is a natural number greater than 1 that has exactly two distinct positive divisors: 1 and the number itself. In simple terms, a prime number cannot be formed by multiplying two smaller natural numbers together. The sequence of prime numbers begins with 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. Any natural number greater than 1 that has more than two positive divisors is known as a composite number. For example, 12 is a composite number because it can be divided evenly by 1, 2, 3, 4, 6, and 12. Meanwhile, the numbers 0 and 1 occupy a special category in number theory. They are classified as neither prime nor composite because 1 has only a single positive divisor, while 0 can be divided by any non-zero integer without leaving a remainder. A few fascinating mathematical properties make prime numbers unique. First, the number 2 is both the smallest prime number and the only even prime number in existence. Every other even number is automatically divisible by 2,...

How to Find the Square Root of a Number in Python (Without Importing Any Libraries)

Calculating the square root of a number is a great way to practice basic arithmetic and string formatting in Python. In the video below, we walk through a simple script that computes the square root using pure math without importing any external libraries. Python Code: Square Root Calculator You can run this code directly in any Python environment by changing the value assigned to number : number = 4 number_sqrt = number ** 0.5 print('The square root of %0.3f is %0.3f' % (number, number_sqrt)) Sample Output The square root of 4.000 is 2.000 How This Script Works Set the Input Value: We assign the integer 4 to the variable number . You can swap this with any positive number or decimal. Calculate Using the Exponent Operator ( ** ): In mathematics, raising a number to the power of 0.5 (one-half) is identical to taking its square root. Python computes number ** 0.5 natively and stores the result in number_sqrt . Format the Output: The %0.3f pl...

How to Find the Factorial of a Number in Python (Using If-Else & Loops)

Calculating the factorial of a number is one of the best ways to practice conditional statements and loops in Python. In the video below, I walk through a clean Python script that handles negative numbers, zero, and positive integers step by step. Python Code: Factorial Calculator You can test this script right away by changing the value assigned to number : # This script calculates the factorial of a hard-coded number # Tweak the input value below to test different results number = 5 factorial = 1 # Check whether the number is negative, zero, or positive if number < 0: print("Factorials do not exist for negative numbers.") elif number == 0: print("The factorial of 0 is 1.") else: for i in range(1, number + 1): factorial = factorial * i print(f"The factorial of {number} is {factorial}") Sample Output The factorial of 5 is 120 How This Script Works Initialize Variables: We set number = 5 as our test input an...

Calculate the Area of a Triangle in Python Using Heron's Formula

When you only know the lengths of a triangle's three sides—and not its height— Heron's formula lets you calculate the exact area in just a few lines of Python. Watch my quick 60-second walkthrough below, or copy the complete script to test it yourself. Python Code: Heron's Formula No external libraries are required for this script—everything runs using standard Python math operators. # This program calculates a triangle's area using Heron's formula # Define the three side lengths (equilateral triangle example) a = 6 b = 6 c = 6 # Calculate the semi-perimeter s = (a + b + c) / 2 # Calculate the final area area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Print the result rounded to 2 decimal places print(f"The area of the triangle is {area:.2f}") Sample Output The area of the triangle is 15.59 How This Script Works Define Side Lengths: Variables a , b , and c store the three sides of the triangle (set to 6 each in this example). ...

Rewiring Global Finance: How India's Tech Hubs are Forging the Future with AI and Tokenization

Image
How AI and Tokenization Are Reshaping Global Finance Financial institutions are increasingly pairing Artificial Intelligence (AI) with asset tokenization to speed up settlements, automate compliance, and manage risk in real time. Much of this engineering work is being built out of major technology hubs in India, where global banking teams are testing how automated AI models and blockchain-based ledgers can work side by side in production. Broadridge's India Teams: Architects of Financial Evolution Leading the charge in this transformative era are dedicated teams within major financial technology firms, with a particular focus on the deep talent pools in India. These innovation hubs are not merely executing tasks, they are conceptualizing, developing, and deploying the cutting-edge solutions that will underpin future financial markets. Their strategic importance cannot be overstated, acting as crucial engines for global financial innovation. Strategic Talent Pool:  India offers a ...