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.

What will be an ideal response?

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

If you turn off the ________, you can open a message in a new window by double-clicking the message in the message list

Fill in the blank(s) with correct word

Computer Science & Information Technology

Consider the following class definitions:class bClass{public:void set(double a, double b);//Postcondition: x = a; y = b;void print() const;bClass();//Postcondition: x = 0; y = 0;bClass(double a, double b);//Postcondition: x = a; y = b;private:double x;double y;};class dClass: public bClass{public:void set(double a, double b, double c);//Postcondition: x = a; y = b; z = c;void print() const;dClass();//Postcondition: x = 0; y = 0; z = 0 ;dClass(double a, double b, double c);//Postcondition: x = a; y = b; z = c;private:double z;};Which of the following dClass constructor definitions is valid in C++?

A. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } B. dClass::dClass(double a, double c) { x = a; z = c; } C. dClass::dClass(double a, double b) : bClass() { x = a; y = b; } D. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

Computer Science & Information Technology