'''
Created on Jun 17, 2013

@author: Jared

This is a short example to illustrate the use of accessing substrings in Python.
The program asks the user to enter a string and
also a particular substring to search for within the first string.
The program will print out the starting index of every matching substring.

Python translation of Arup's Java code
'''

def main():                                                  
    # Get user input.
    text = input("Enter a string.\n")
    pattern = input("Enter the substring to search for.\n")
                                                        
    num_matches = 0
                                                        
    # Search for string at each possible starting index.
    for i in range(len(text) - len(pattern) + 1):                                  
        # Check the individual substring in question for equality.
        if (text[i: i + len(pattern)] == pattern):
            print("There is a match at index " + str(i))
            num_matches += 1                                                                               
                                                        
    # Print out a message if no matches were found.
    if (num_matches == 0):
        print("Sorry, there are no matches.")
      
# runs main module on startup
if __name__ == "__main__":
    main()
