# Category: Python Programming Examples

python tutorials and learn python

### 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,…

### Python Program for Tower of Hanoi

Python Program for Tower of Hanoi Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

### 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 Find sum of odd factors of a number Given a number n, the task is to find the odd factor sum. Examples: Input : n = 30 Output : 24 Odd dividers sum 1 + 3 + 5 + 15 = 24 Input : 18 Output : 13 Odd dividers sum 1…

### Python Program for Product of unique prime factors of a number

Python Program for Product of unique prime factors of a number Given a number n, we need to find the product of all of its unique prime factors. Prime factors: It is basically a factor of the number that is a prime number itself. Examples: Input: num = 10 Output: Product is 10 Explanation: Here,…

### 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…

### 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…