Check Binary Number or not

PHOTO EMBED

Tue Dec 20 2022 06:41:48 GMT+0000 (Coordinated Universal Time)

Saved by @sukumar #python

# 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')
content_copyCOPY