Check if a given string is binary or not.

In this program, we will take a string as input and check if a given string is binary or not.

Steps to solve the program
  1. Take a string as input.
  2. Create a variable count and assign its value equal to 0.
  3. Use for loop to iterate over each character in the string.
  4. If the character is 0 or 1 then add 1 to the count variable.
  5. If the value of the count variable is equal to the length of the string then string is binary.
  6. Print the output.
				
					#Input string
str1 = "01011100"
count = 0

for char in str1:
    if char == "0" or char == "1":
        count += 1

#Printing output
if count == len(str1):
    print("Yes")
else:
    print("No")
    
    
str1 = "sqatools 100"
count = 0

for char in str1:
    if char == "0" or char == "1":
        count += 1
        
if count == len(str1):
    print("Yes")
else:
    print("No")
				
			

Output :

				
					Yes

No
				
			

remove the kth element from the string

add ‘ing’ at the end of the string

Leave a Comment