You are required to implement a Python function that counts the number of sentences and words in a given text string. The function should be named count_sentences_and_words and it must accept a single string argument and return a tuple containing the counts of sentences and words.
Functionality Requirements
Count Sentences: A sentence is defined as a sequence of characters ending with one of the following punctuation marks: period (.), exclamation mark (!), or question mark (?).
Count Words: A word is defined as a sequence of characters separated by spaces. The function should count the total number of words in the text.
Input/Output Requirements
Input: The function will take a single parameter:
text (str): A string containing the text to be analyzed. The string may include sentences separated by various whitespace characters and may contain punctuation marks.
Output: The function will return a tuple:
(sentences, words): where sentences is the number of sentences (int) and words is the number of words (int) in the input text.
Implementation
You will need to:
Create a file named /app/solution.py.
Implement the count_sentences_and_words function as per the provided specifications.
Example
Input: "Hello world! How are you? I am fine."
Output: (3, 7)
Explanation: There are 3 sentences and 7 words in the input text.
Ensure your implementation handles various cases, including:
Multiple spaces between words.
Sentences ending with different punctuation marks.