Sunday, 8 September 2013

string operations, for loop doesnt work

string operations, for loop doesnt work

I have written this to get the index of first character of string s1 which
has come in string s2, but doesn't give the correct answer and every time
it throws different wrong answers, anyone knows why?
s1 = input ('enter the s1 string: ')
s2 = input ('enter the s2 string: ')
for i in range (0, len(s1)):
if s1[i] in s2:
n= (s1.index(s1[i]))
else:
n= -1
print (n)

No comments:

Post a Comment