Q)write a program to check at which position digits are same and print the position at which they are same.
for example, if n1=1234453 and n2=2444853 print Same at 1's position
Same at 10th position
Same at 1000th position
how to fix this so it works? it display's 3th position instead of 100th?
n1=int(input())
n2=int(input())
ns1=str(n1)
ns2=str(n2)
l1=len(ns1)
for x in ns1:
for y in ns2:
if x==y:
if int(ns1.index(x))==int(ns2.index(y)):
print("Same at %dth position"%(ns1.index(x))
else:
print("No digits are same")
else:
print("No digits are same")
Aucun commentaire:
Enregistrer un commentaire