# input as Number
n=int(input('enter number:'))
temp=n
while(n!=0):
rem=n%10
if rem!=0 and rem!=1:
print(temp,'is not Binary Number')
break
n=n//10
else:
print(temp,'is Binary Number')
(OR)
# input as String
n=input('enter number:')
lis=['1','0']
for i in n:
if i not in lis:
print(n,'is not Binary Number')
break
else:
print(n,'is Binary Number')
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter