Table-5 Exercises

< CS101

For these exercises, write code to count names which meet certain conditions and when the loop is done, print a line like the following to report the count.

count: 23

Optionally, you can print out the names in your loop to see what your code is doing, so long as the "count: 23" is printed last.

The code to produce the above line looks like following, but the real work is in initializing and updating the count variable (or whatever variable you use).

print("count:", count);

The starter code includes the standard count = 0; line to set count to zero before starting.

1. Write code to count and print number of names starting with the letter "L". The last line printed should look like the "count: 23" example above (note: the answer is not 23, that's just a number I made up).


table-5-ex1

 

2. (Variant of above) Write code to count and print the number of names not starting with the letter "L" in the "count: 23" format. Maybe don't print the names themselves for this one, as there are very many of them.


table-5-ex2

 

3. Write code to count and print number of girl names starting with "T" in the "count: 23" format.


table-5-ex3

 

4. Write code to count and print the number of boy names ending with "d" in the "count: 23" format.


table-5-ex4

 

5. How many names ending in "m" are there with a rank <= 500? Write code to count and print this number in the "count: 23" format.


table-5-ex5

 


Each click of a Run button saves that code on the computer running the browser. The button below retrieves the all code exercises listed to the right of the button.

count 5 : table-5-ex1 table-5-ex2 table-5-ex3 table-5-ex4 table-5-ex5

(code appears here)