Artificial Intelligence
Please fill the required field.

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 only


You can achieve this by writing a simple program that checks the input for non-alphabetic characters. If the input contains any characters that are not letters, the program will prompt the user to enter a valid sentence. If the input is valid, it will reverse the letters in each word and print the result. Here's a sample code implementation in Python: ```python def reverse_words(sentence): words = sentence.split() reversed_words = [word[::-1] for word in words] # Reverse each word return ' '.join(reversed_words) def main(): user_input = input("Please enter a sentence: ") if any(not char.isalpha() and not char.isspace() for char in user_input): print("Please enter a sentence with letters only.") else: result = reverse_words(user_input) print(result) if __name__ == "__main__": main() ``` ### How it works: 1. The program prompts the user for input. 2. It checks if the input contains any non-alphabetic characters (excluding spaces). 3. If non-alphabetic characters are found, it prompts the user to try again. 4. If the input is valid, it reverses each word in the sentence and joins them back into a single string, which is then printed. ### Example Outputs: - **Input:** Hello World **Output:** olleH dlroW - **Input:** Hello 550! **Output:** Please enter a sentence with letters only.