# Author: James Tam # Version: November, 2013 # Learning concepts: # Using the len() function in conjunction with strings # Using string slicing for a practical example (determining file # type as specified by file name suffix) MAX_FILE_LENGTH = 256 SUFFIX_LENGTH = 3 filename = input("Enter new file name (max 256 characters): ") if (len(filename) > MAX_FILE_LENGTH): print("File name exceeded the max size of %d characters, you bad" %(MAX_FILE_LENGTH)) else: # Find file type, last three characters in string e.g., resume.txt endSuffix = len(filename) startSuffix = endSuffix - SUFFIX_LENGTH suffix = filename[startSuffix:endSuffix] if (suffix == "txt"): print("Text file") print("%d:%d %s" %(startSuffix,endSuffix,suffix))