Write a function that counts the characters in a string the user inputs. Then write a routine that calls the function and displays the following output.
$ ./count_letters.py
Enter some words: The rain in Spain
The string "The rain in Spain" has 17 characters in it.
$ cat count_letters.py
#!/usr/bin/python
def countEm(my_string):
count = 0
for s in my_string:
count += 1
return count
stg = raw_input('Enter some words: ')
print 'The string \"' + stg + '\"' + ' has ',
print countEm(stg),
print 'characters in it.'
Computer Science & Information Technology
You might also like to view...
When you are working with framesets, there is only one way in which a particular problem can be solved.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
Describe the habits of successful interface designers.
What will be an ideal response?
Computer Science & Information Technology