+ 1

'DIGIT' :What is the solution of this coding in python3.6?? I want to know urgent...

You are provided with a number D containing only digits 0's and 1's. Your aim is to convert this number to have all the digits same. For that, you will change exactly one digit i.e. from 0 to 1 or from 1 to 0. If it is possible to make all digits equal (either all 0's or all 1's) by flipping exactly 1 digit then output "YES", else print "NO" (quotes for clarity). Input Format: The first line of the input contains the number D made of only digits 1's and 0's. Output: Print 'YES' or 'NO' depending on whether its possible to make it all 0s or 1s or not. Example-1: Input: 101 Output: YES Example-2: Input: 11 Output: NO Explanation: In the first example, it is possible to make all the digits same by flipping the middle digit from 0 to 1. In the second example it is not possible.

4th Oct 2018, 8:51 PM
shivam Kumar
shivam Kumar - avatar
5 ответов
+ 2
Where is your try?
4th Oct 2018, 9:22 PM
KrOW
KrOW - avatar
+ 2
You are given a number A which contains only digits 0's and 1's. Your task is to make all digits 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 same by just flipping one digit then print 'YES' else print 'NO'. Input Format: The first line contains a number made up of 0's and 1's. Output Format: Print 'YES' or 'NO' accordingly without quotes.
12th Aug 2019, 1:39 PM
Ketha Baby Sushmitha
Ketha Baby Sushmitha - avatar
+ 1
T = int(input()) while T > 0: num =input() zeros = 0 for c in num: if c == '0': zeros += 1 if zeros == 1 or zeros == len(num)-1: print ('YES') else: print ('NO') T -= 1 Now please help to completely solve my coding
4th Oct 2018, 10:00 PM
shivam Kumar
shivam Kumar - avatar
+ 1
shivam Kumar Simplify the problem... Your output is YES if count of 1 or 0 is exactly one, right? Then you can read any digit (1 or 0), store count of either in 2 vars (zeros and ones at example), augment at any iteration relative counter. After you can do a check: if either are greater than 1, then you cannot get an all similar digit by flipping one digit and return NO, else continue.. Example: In: 1101010 1) ones: 1 zero:0 2) ones:2 zero:0 3) ones:2 zeros:1 4) ones:3 zeros:1 5) ones:3 zeros:2 In this iteratiom either are greater than 1 then you can return "NO" without read futher input
5th Oct 2018, 7:35 AM
KrOW
KrOW - avatar
+ 1
num =input() zeros = 0 for c in num: if c == '0': zeros += 1 if zeros == 1 or zeros == len(num)-1: print ('YES') else: print ('NO')
21st Aug 2019, 5:30 PM
Kavitha P
Kavitha P - avatar