Program-3

You are given input which contains only digits 0's and 1's. Your task is to make all digits the same by just flipping one digit (i.e. 0 to 1 or 1 to 0) only. If it is possible to make all the digits the same by just flipping one digit then return True else return False.


n=input("Enter the number: ")
z=0
o=0
for i in range(0,len(n)):
ch=n[i]
if ch=='0':
z=z+1
else:
o=o+1
if(z==1 or o==1):
  print("True")
else:
  print("False")
Sample input and output
Enter the number: 1110
 True
Enter the number:  11001
False


No comments:

Post a Comment