You are on page 1of 3

Assignment 1:Digits

def isFlip(n):

zer=0

on=0

print("You entered: ",n)

for ch in n:

if(ch=='0'):

zer+=1

elif(ch=='1'):

on+=1

print("zero=",zer," one= ",on)

return zer,on

no=input("Enter a binary number:- ")

zero,one=isFlip(no)

if zero>1 and one>1:

print("No. It is not possible to flip a single digit to make all the digits same.")

else:

print("Yes. It is possible to flip a single digit to make all the digits same.")

Assignment 3:Semi Primes


N=int(input("Enter a number to check whether it can be expressed as a sum of two semi-primes:- "))

def isPrime(n):

c=0

if n>1:
for t in range(2,n):

if(n%t)==0:

c=c+1

if c==0:

return True

else:

return False

for i in range(2,N+1):

first=isPrime(i)

second=isPrime(N-i)

if first==True and second==True:

print("Yes, it is possible to represent entered number as a sum of two semi-primes.")

break

else:

continue

Assignment 4: Special Character


N=int(input("Enter a number to check whether it can be expressed as a sum of two semi-
primes:- "))
def isPrime(n):
c=0
if n>1:
for t in range(2,n):
if(n%t)==0:
c=c+1
if c==0:

return True
else:
return False
for i in range(2,N+1):
first=isPrime(i)
second=isPrime(N-i)
if first==True and second==True:
print("Yes, it is possible to represent entered number as a sum of two semi-primes.")
break
else:
continue

You might also like