def correctlyFormattedName(name): """returns true if a name is in the format LastName, FirstName""" if len(name)==0: return False if name[0] == ",": return False index=0 #look for the comma with a while loop while (index < len(name)) and (name[index] != ","): index += 1 #if there is a comma and there's text after it, return true if index < len(name)-1: return True else: return False name = "" #use the function to check if the name is formatted correctly while not correctlyFormattedName(name): name = raw_input("Please enter your name in the format 'LastName, FirstName': ") print "\n" + name