Your "z" variable is wrong. You should make so it starts from 1 (to compare next letter in the strings; you already compared letters in i and j, so now you should compare i+1 and j+1) and ends on last letter of shorter string.
i_first - i
and
j_first - j
should measure how many characters left to compare in each string so you just have to pick the minimum from them as follows:
for z in range(1, min(i_first - i, i_second - j)):
Also from the way you declared it your counter1 variable should start from 1, not 0 becuse you already found one letter in common. Similarly your pos_count1 should start with the found letter:
counter1 = 1
pos_count1=file_first[i]
ii and jj variables don't register first nor last position of found substring, they're just wrong... If you wanted them to be first position of a substring in your strings instead then you can use .index() method, for example:
str = "not a substring"
pos = str.index("substring")
print(pos)
Your print function at the end is way too long for one line so it's better to either break it with enters or split into few prints.
2 extra tips:
range(0, 5)
is the same as
range(5)
and this:
var = var + 1
is the same as
var += 1
Here's corrected code:
file_first="AACCGTTTGATTG"
file_second="AACGTTTGAGCTG"
i_first=len(file_first)
i_second=len(file_second)
counter=0
pos_count=""
for i in range(i_first):
for j in range(i_second):
if (file_first[i]==file_second[j]):
counter1 = 1
pos_count1=file_first[i]
for z in range(1, min(i_first - i, i_second - j)):
if file_first[i+z] == file_second[j+z]:
counter1 += 1
pos_count1 += file_first[i+z]
else:
break
if counter1>counter :
counter=counter1
pos_count=pos_count1
print(" the counter is ",counter)
print("postion is :",pos_count)
print("postion in first file is :", file_first.index(pos_count))
print("postion in second file is :", file_second.index(pos_count))