# Python

## Convert floating to binary in Python

In this Python program, we will have a look at “How to convert floating point decimal number to binary number?” Python Program to Convert floating to binary def float_bin(number, places = 3): whole, dec = str(number).split(“.”) whole = int(whole) dec = int (dec) res = bin(whole).lstrip(“0b”) + “.” for x in range(places): whole, dec = …

## Check whether a number has consecutive 0’s in Python

In this Python Program, we will check if the given number has consecutive 0’s . Python Program to check whether a number has a consecutive 0’s #codeatglance python program def result(N, K): z = toK(N, K) if (check(z)): print(“Yes”) else: print(“No”) def toK(N, K): # Weight of each digit w = 1 s = 0 …

## Triangular Matchstick Number In Python

This Python program will help you to print the total number of a matchstick that is required to form a pyramid of matchsticks of x floors, where X represents the total number of floors. Python Program To find Triangular Matchstick Number def numOfSticks(x): return (3 * x * (x + 1)) / 2 print(int(numOfSticks(5))) Output: …

## Legendre\’s Conjecture In Python

This Python program will help you to verify Legendre\’s Conjecture. According to Wikipedia “conjecture is a conclusion or proposition based on incomplete information, for which no proof or disproof has yet been found. Conjectures such as the Riemann hypothesis or Fermat’s Last Theorem have shaped much of mathematical history as new areas of mathematics are …

## Check if a string contains all unique characters in Python

This Python Program will help you check “if a string contains all unique characters” Python Program To Check If a string contains all unique characters def isUniqueChars(st): if len(st) > 256: return False char_set = [False] * 128 for i in range(0, len(st)): val = ord(st[i]) if char_set[val]: return False char_set[val] = True return True …

## Copy odd lines of one file to other in Python

This python program will read the contents of one file and copy the content of the odd line into the new file. Steps to write & execute the program: Open the first file in read mode. Assign the first file to f1. Open the second file in write mode. Assign the second file to f2. …