Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

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 the contents of a file and copy only the content of odd lines into a new file. Examples: Input : Hello World Python Language Output : Hello Python Input : Python Language Is Easy Output : Python…
Read more

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…
Read more

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…
Read more

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…
Read more

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…
Read more

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,…
Read more

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…
Read more

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…
Read more

Python Program for Check if all digits of a number divide it

Python Program for Check if all digits of a number divide it Given a number n, find whether all digits of n divide it or not. Examples: Input : 128 Output : Yes 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Input : 130 Output : No…
Read more

Python Program for Find sum of even factors of a number

Python Program for Find sum of even factors of a number Given a number n, the task is to find the even factor sum of a number. Examples: Input : 30 Output : 48 Even dividers sum 2 + 6 + 10 + 30 = 48 Input : 18 Output : 26 Even dividers sum…
Read more