Table 6 Exercises

< CS101

Each of the following problems asks you to count two things. The last lines printed should look like:

count: 23
count: 42

For simplicity, we will just use the word "count" for both lines in the output. As usual, you can print and count some cases by hand to check your code before submit time.

1.

Do more baby names start with "A" or "B"? Write code to count and print those two counts ("A" count, then "B" count).


table-6-ex1

 

2.

Same as problem 1, but instead of printing out the counts, just print whether more names start with "A" or "B". The lines of output should look something like: "More names start with A than with B" or "The same number of names start with A and B".


table-6-ex2

 

3.

Now we'll look at the survey data. How many people identified "Friends" vs. "Game of Thrones" as their favorite TV show? The appropriate field in the survey is "tv", and think about uppercase vs. lowercase letters in your query code. Write code to count and print those two values ("Friends" count, then "Game of Thrones" count).


table-6-ex3

 

4.

Instead of looking at the whole survey, let's look only at the people who identified "green" as their favorite color. Produce the same tv-show counts as the previous question, but looking only at people who identified "green" as their favorite color.


table-6-ex4

 


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 4 : table-6-ex1 table-6-ex2 table-6-ex3 table-6-ex4

(code appears here)