Artificial Intelligence
Please fill the required field.

simplify: If the input contains non-alphabetic characters, prompt the user to "Please enter a sentence with letters only." Eg 1: Input: Hello World Output: olleH dlroW Eg 2: Input: Hello 550! Output: Please enter a sentence with letters


To simplify the task, we can structure it as follows: 1. Prompt the user for input. 2. Check if the input contains only alphabetic characters (and spaces if necessary). 3. If it does, reverse each word and return the modified string. 4. If it doesn't, prompt the user to enter a valid sentence. Here's a simplified version of the logic: ```python def reverse_words(input_string): # Check for non-alphabetic characters if not all(c.isalpha() or c.isspace() for c in input_string): return "Please enter a sentence with letters only." # Split the input into words, reverse each word, and join them back reversed_string = ' '.join(word[::-1] for word in input_string.split()) return reversed_string # Example Inputs input1 = "Hello World" input2 = "Hello 550!" print(reverse_words(input1)) # Output: olleH dlroW print(reverse_words(input2)) # Output: Please enter a sentence with letters only. ``` This function will output either the reversed words of a valid alphabetic sentence or a request for valid input if the initial check fails.