# Category: Python Programming Examples

python tutorials and learn python

### Python program to copy odd lines of one file to other

Python program to copy odd lines of one file to other Write a python program to read contents of a file and copy only the content of odd lines into new file. Examples: Input : Hello World Python Language Output : Hello Python Input : Python Language Is Easy Output : Python Is Approach to…

### Python program to check if a string contains all unique characters

Python program to check if a string contains all unique characters To implement an algorithm to determine if a string contains all unique characters. Examples: Input : s = “abcd” Output: True “abcd” doesn’t contain any duplicates. Hence the output is True. Input : s = “abbd” Output: False “abbd” contains duplicates. Hence the output…

### Python Program for Legendre\’s Conjecture

Python Program for Legendre\’s Conjecture It says that there is always one prime number between any two consecutive natural number\’s(n = 1, 2, 3, 4, 5, …) square. This is called Legendre\’s Conjecture. Conjecture: A conjecture is a proposition or conclusion based upon incompleate information to which no proof has been found i.e it has…

### Python Program for Triangular Matchstick Number

Python Program for Triangular Matchstick Number Given a number X which represents the floor of a matchstick pyramid, write a program to print the total number of matchstick required to form a pyramid of matchsticks of x floors. Examples: Input : X = 1 Output : 3 Input : X = 2 Output : 9…

### Python Program for Number of solutions to Modular Equations

Python Program for Number of solutions to Modular Equations Given A and B, the task is to find the number of possible values that X can take such that the given modular equation (A mod X) = B holds good. Here, X is also called a solution of the modular equation. Examples: Input : A…

### Check whether a number has consecutive 0’s in the given base or not

Check whether a number has consecutive 0’s in the given base or not Given a decimal number N, the task is to check if a number has consecutive zeroes or not after converting the number to its K-based notation. Examples: Input: N = 4, K = 2 Output: No 4 in base 2 is 100,…

### Python program to convert floating to binary

Python program to convert floating to binary Python doesn’t provide any inbuilt method to easily convert floating point decimal numbers to binary number. So, Let’s do this manually. Approach : To convert a floating point decimal number into binary, first convert the integer part into binary form and then fractional part into binary form and…

### Python program to convert float decimal to Octal number

Python program to convert float decimal to Octal number Python doesn’t support any inbuilt function to easily convert floating point decimal numbers to octal representation. Let’s do this manually. Approach : To convert a decimal number having fractional part into octal, first convert the integer part into octal form and then fractional part into octal…