Character Count
1. Stating the problem: We need to write a Python function, count_characters(s), that takes a string input and returns a dictionary counting each character's occurrences in a case-insensitive manner.
2. Validate the input: The function should check that the input string is non-empty and contains only alphabetic characters (A-Z or a-z). If invalid, return the error message "Input must contain only alphabetic characters."
3. Convert the input string to lowercase to treat uppercase and lowercase characters the same.
4. Iterate over the lowercase string and count the occurrences of each character using a dictionary.
5. Return the dictionary with keys as lowercase characters and values as their counts.
6. Example: For input "DataScience", converting to lowercase gives "datascience". Counting characters yields:
$$\{'d':1, 'a':2, 't':1, 's':1, 'c':2, 'i':1, 'e':2, 'n':1\}$$
7. For invalid input like "Machine Learning" with space, the function will return the error message.
Here is the implementation:
```python
def count_characters(s):
if not s or not s.isalpha():
return "Input must contain only alphabetic characters."
s = s.lower()
char_count = {}
for char in s:
char_count[char] = char_count.get(char, 0) + 1
return char_count
# Example usage
s = input()
print(count_characters(s))
```
This function ensures case-insensitive counting and validates input as required.