Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python Program for Sieve of Eratosthenes

Python Program for Sieve of Eratosthenes Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7,…
Read more

Python Program for Tower of Hanoi

Python Program for Tower of Hanoi Introduction The Tower of Hanoi is a classic problem in computer science and mathematics. It was introduced by the French mathematician Édouard Lucas in 1883. The problem involves moving a stack of disks from one rod to another under certain constraints. In this blog post, we will explore the…
Read more

Python Program for Coin Change

Python Program for Coin Change Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn\’t matter.

Python Program for Find sum of odd factors of a number

Python Program for Finding the Sum of Odd Factors of a Number In this blog post, we will delve into a Python program that calculates the sum of the odd factors of a given number. We’ll discuss the algorithm used and provide a complete Python code example with detailed explanations. Problem Statement: Given a positive…
Read more

Python Program for Product of unique prime factors of a number

Python Program: Product of Unique Prime Factors of a Number In this blog post, we’ll delve into a Python program designed to calculate the product of the unique prime factors of a given number. We’ll provide a comprehensive explanation of the algorithm, present the Python code, and include examples with corresponding outputs. Understanding the Algorithm…
Read more

Python Program for Efficient program to print all prime factors of a given number

Python Program for Efficient program to print all prime factors of a given number Given a number n, write an efficient function to print all prime factors of n. For example, if the input number is 12,

Python Program for Find largest prime factor of a number

Python Program for Find largest prime factor of a number Given a positive integer \’n\'( 1 <= n <= 1015). Find the largest prime factor of a number. Input: 6 Output: 3 Explanation Prime factor of 6 are- 2, 3 Largest of them is \’3\’ Input: 15 Output: 5 Python3 Python3 # Python3 code to…
Read more

Python Program to Reverse a linked list

Python Program to Reverse a linked list Given pointer to the head node of a linked list, the task is to reverse the linked list. We need to reverse the list by changing links between nodes. Examples: Input : Head of following linked list 1->2->3->4->NULL Output : Linked list should be changed to, 4->3->2->1->NULL Input…
Read more

Python program to convert time from 12 hour to 24 hour format

Python Program to Convert Time from 12-Hour to 24-Hour Format Introduction Time representation in 12-hour and 24-hour formats is common in various applications. Converting time from a 12-hour format (AM/PM) to a 24-hour format is a useful task in programming. This Python program demonstrates how to convert time from the 12-hour format to the 24-hour…
Read more

Python 3 | Program to print double sided stair-case pattern

Python 3 | Program to print double sided stair-case pattern Below mentioned is the python 3 program to print the double sided stair case pattern. Examples: Input : 10 Output : * * * * * * * * * * * * * * * * * * * * * * * *…
Read more