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...

[Ben Wiedermann] Describe in clear English or pseudocode a decision procedure to answer the question: “Given a list of integers N and an individual integer n, does N correspond to a prime factorization of

What will be an ideal response?

Computer Science & Information Technology

After installing a new video card, the computer displays no video output. Which of the following is the most likely cause?

A) The video cable must be upgraded to accommodate the new capabilities of the video card. B) The video card is defective. C) The video card is incompatible with the system. D) The video card does not have the power connector attached.

Computer Science & Information Technology

_____ messages appear as ScreenTips next to the active cell.

A. Value B. Input C. Key D. User

Computer Science & Information Technology

A _____ is a detailed description of when project activities are performed.

a. project critical path b. project deadline c. project schedule d. project milestone

Computer Science & Information Technology