Python Exercise Example17
# Python2.x Python Exercise Instance 17
[ Python 100 Examples](#)
**Question:** Input a line of characters, and separately count the number of 1. Please enter a string. letters, spaces, digits, and other characters.
**Program Analysis:** Use a while or for statement, with the condition that the input character is not 'n'.
## Instance (Python2.x) - Using while loop
```python
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import string
s = raw_input('Please enter a string:n')
letters = 0
space = 0
digit = 0
others = 0
i=0
while i<len(s):
c = s
i += 1
if c.isalpha():
letters += 1
elif c.isspace():
space += 1
elif c.isdigit():
digit +=
YouTip