-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq3 Digits.py
45 lines (43 loc) · 1.16 KB
/
q3 Digits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 13 12:20:51 2019
@author: Satvik Chachra
"""
# =============================================================================
# Programming Assignment-3: Digits
# Due on 2019-08-22, 23:59 IST
# 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.
#
# Example:
#
# Input:
#
# 101
#
# Output:
# YES
#
# Explanation:
# If you flip the middle digit from 0 to 1 then all the digits will become same. Hence output is YES.
#
# =============================================================================
x = list(input())
counto = 0
countn = 0
for i in range(len(x)):
if(x[i]=='0'):
counto = counto+1
elif(x[i] == '1'):
countn = countn + 1
if(counto==1 or countn==1):
print("YES")
else:
print("NO")