Python Programming Examples

Python Programming Examples

Basic Programming Exercises

Python Program to Calculate Body Mass Index (BMI)

Body Mass Index (BMI) is a numerical value calculated based on a person’s weight and height...

Python Program to Convert Decimal to Binary, Octal, & Hexadecimal

In number systems, a decimal number (base 10) can be converted into different formats: In this...

Write a Python Program to Find HCF (GCD)

The Highest Common Factor (HCF), also known as the Greatest Common Divisor (GCD), of two numbers is...

Write a Python Program to Find LCM

The Least Common Multiple (LCM) of two numbers is the smallest positive integer that is divisible by...

Write a Python Program to Find the Sum of Natural Numbers

Natural numbers are positive integers starting from 1, 2, 3, 4, 5, … and so on. The sum of...

Write a Python Program to Check Armstrong Number

An Armstrong number (also known as a narcissistic number) is a number that is equal to the sum of...

Write a Python Program to Print the Fibonacci sequence

The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding...

Write a Python Program to Find the Factorial of a Number

The factorial of a number is the product of all positive integers from 1 to that number. It is...

Write a Python Program to Check Prime Number

A prime number is a natural number greater than 1 that has only two factors: 1 and itself. Some...

Write a Python Program to Check Leap Year

A leap year occurs every four years to keep our calendar in sync with Earth’s revolutions...

Write a Python program to solve quadratic equation

A quadratic equation is a second-degree polynomial equation of the form: ax2+bx+c=0 where a, b, and...

Write a Python program to convert Celsius to Fahrenheit

Problem: Write a Python program to convert Celsius to Fahrenheit. Formula to Convert Celsius to...

Write a Python program to convert kilometers to miles

Problem: Write a Python program to convert kilometers to miles. Formula to Convert Kilometers to...

Find Two Missing Numbers in an Array using Python

Introduction In the world of computer science and programming, efficient algorithms are like hidden...

Swapping Two Numbers Without a Third Variable in Python

Introduction In the world of programming, efficiency and elegance are highly valued attributes. One...

Write a Python Program to Count the Number of Lines in a Text File

Introduction In the world of programming, text files are a common medium for storing and sharing...

Python Program to Display Words Starting with a Vowel and Ending with a Digit from a Text File

Introduction Text processing is a core aspect of programming, and the ability to extract specific...

Python Program to Calculate Age in Years Months and Days

Introduction In the world of programming, there are countless real-life scenarios where the need to...

Learn 25+ Important Pattern Programs in Python

Introduction Patterns are an essential aspect of programming that can be both fun and challenging to...

Finding the Next Smallest & Largest Numbers with the Same Number of 1 Bits in Python

Introduction In the realm of computer science and binary mathematics, a fascinating challenge is...

Counting the Number of Bits to Convert Integer A to B using Python

Introduction In the realm of computer science and digital systems, the manipulation of binary data...

Sorting

Understanding Quick Sort Algorithm in Python

Introduction Sorting is a fundamental operation in computer science, and there are various...

Implementing Merge Sort in Python

Introduction Sorting is a fundamental operation in computer science and plays a crucial role in...

Understanding Selection Sort in Python

Introduction Sorting is a fundamental operation in computer science and plays a crucial role in...

Introduction to Insertion Sort in Python

Introduction Insertion sort is a simple yet efficient sorting algorithm that builds the final sorted...

Bubble Sort in Python: A Simple Sorting Algorithm

Introduction When it comes to sorting a list or an array, there are numerous algorithms available...

Understanding Counting Sort in Python

Introduction Sorting is a fundamental operation in computer science that involves arranging elements...

Understanding Radix Sort in Python

Introduction Sorting algorithms play a crucial role in computer science and programming. They allow...

Data Structure

Exploring Linked Lists in Python: Implementation and Operations

Introduction Linked lists are fundamental data structures used in computer science and programming...

Remove Duplicate Nodes from a Linked List using Python

Introduction A linked list is a data structure consisting of a sequence of elements called nodes...

Reversing a Linked List in Python: Iterative and Recursive Methods

Introduction A linked list is a fundamental data structure used in computer science and programming...

Adding Two Numbers Represented by Linked Lists in Python using Reverse Method

Introduction Linked lists are a popular data structure used to store a sequence of elements. They...

Adding Two Numbers Represented by Linked Lists in Python using Forward Method

Introduction Linked lists are a versatile data structure often used to handle large numbers that...

Exploring Palindrome Detection in a Linked List with Python

Introduction A linked list is a popular data structure that consists of a series of nodes, where...

Understanding Linear Search in Python

Introduction Searching for a specific element in a list or an array is a fundamental operation in...

Binary Search in Python: Iterative and Recursive Methods

Introduction Binary search is a powerful algorithm used to efficiently locate a specific value...

Exploring Graphs with Depth-First Search in Python

Introduction Depth-First Search (DFS) is a fundamental graph traversal algorithm used to...

Exploring Graphs with Breadth-First Search in Python

Introduction Graphs are an essential data structure used in computer science and various real-world...

Strings

URLify a Given String using Python

Introduction In the digital age, the internet has become an integral part of our lives. We often...

Find the Last Occurrence of a Vowel in a Given String in Python

Introduction When working with strings in Python, it’s often necessary to manipulate and...

Checking for Unique Characters in a String using Python

Introduction When working with strings in Python, there are often situations where you need to...

Check Permutation of Two Strings in Python

Introduction In the realm of string manipulation and algorithmic problem-solving, determining...

Writing a Python Program for String Compression

Introduction Have you ever stared at a massive text file and wished there was a way to shrink it...

Sorting Strings in Python without Using the Sort Function

Introduction Sorting is a fundamental operation in programming that arranges elements in a specific...