## Python Program to Find the Roots of a Quadratic Equation

This is a Python Program to find the roots of an equation. Problem Description The program takes the coefficients of an equation and finds the roots of the equation. Problem Solution 1. Take in the coefficients of the equation and store it in three separate variables. 2. Find the value of the discriminant, d. 3. … Read more

## Python Program to Clear the Rightmost Set Bit of a Number

This is a Python program to clear the rightmost set bit of a number. Problem Description A number is given. We have to clear the rightmost set bit of the number. That is, we have to flip the rightmost 1 in the binary representation of n. Problem Solution 1. The function clear_rightmost_set_bit is defined. 2. … Read more

## Python Program to Find Whether a Number is a Power of Two

This is a Python program to find whether a number is a power of two. Problem Description A number is given. The problem is to determine whether the number is a power of two. Problem Solution 1. The function is_power_of_two is defined. 2. It takes a number n as argument and returns True if the … Read more

## Python Program to Count Set Bits in an Integer

This is a Python program to count set bits in a number. Problem Description The program finds the number of ones in the binary representation of a number. Problem Solution 1. Create a function count_set_bits that takes a number n as argument. 2. The function works by performing bitwise AND of n with n – … Read more

## Python Program to Test Collatz Conjecture for a Given Number

This is a Python program to test Collatz conjecture for a given number. Problem Description The Collatz conjecture is a conjecture that a particular sequence always reaches 1. The sequence is defined as: start with a number n. The next number in the sequence is n/2 if n is even and 3n + 1 if … Read more

## Python Program to Read a Number n and Print the Series “1+2+…..+n= “

This is a Python Program to read a number n and print and compute the series “1+2+…+n=”. Problem Description The program takes a number n and prints and computes the series “1+2+…+n=”. Problem Solution 1. Take a value from the user and store it in a variable n. 2. Use a for loop where the … Read more

## Python Program to Find Prime Numbers in a Range using Sieve of Eratosthenes

This is a Python Program to print prime numbers in a range using Sieve of Eratosthenes. Problem Description The program takes a range and prints prime numbers in that range using Sieve of Eratosthenes. Problem Solution 1. Take the value of n from the user. 2. Initialise the sieve with numbers from 2 to n. … Read more

## Python Program to Print the Natural Numbers Summation Pattern

This is a Python Program to read a number n and print the natural numbers summation pattern. Problem Description The program takes a number n and prints the natural numbers summation pattern. Problem Solution 1. Take a value from the user and store it in a variable n. 2. Use two for loop where the … Read more

## Python Program to Print an Inverted Star Pattern

This is a Python Program to read a number n and print an inverted star pattern of the desired size. Problem Description The program takes a number n and prints an inverted star pattern of the desired size. Problem Solution 1. Take a value from the user and store it in a variable n. 2. … Read more 