def evens(the_list): '''evens(list) -> list/boolean Given a list, returns a new list consisting only of those elements with an even index. Returns False if the parameter given is not a list.''' if ( type(the_list) != list ): return False new_list = [] for index in range(0, len(the_list)): if ( index % 2 == 0 ): new_list.append(the_list[index]) return new_list def cat(text_file): '''cat(file) -> Boolean Opens and displays a given text file on screen, line by line. Returns False if the parameter given is not a file.''' if ( type(text_file) != file ): return False for line in text_file: # Since python also prints out the carriage return at the end of each # line of the file, there is no need for us to print out another one # of our own. print line, # Just to make it look neat at the end. Otherwise the console gets a bit # messy looking. print '' def double_my_digits(input): '''double_my_digits(str) -> str/boolean Given a string consisting only of numbers, will return a string obtained by doubling each digit in the input string. Will return False if the input is not a string, or contains something other than what is allowed in an int.''' if ( type(input) != str ): return False try: input = int(input) except ValueError: return False input = str(input) new_string = '' for digit in input: new_string += str(int(digit) * 2) return new_string