]> projects.mako.cc - babynames_answers/blob - answer_2.py
f5b7d001d562bb8131e37658bd23a5c395ca4692
[babynames_answers] / answer_2.py
1 # 2. Are there more boys names or girls names? What about for particular
2 #    letters? What about for every letter?
3
4 import ssadata
5
6 num_boys_names = len(ssadata.boys)
7 num_girls_names = len(ssadata.girls)
8
9 print("total boy names: " + str(num_boys_names))
10 print("total girl names: " + str(num_girls_names))
11
12 for letter in "abcdefghijklmnopqrstuvwxyz":
13     count_boys = 0
14     count_girls = 0
15     for name in ssadata.boys.keys():
16         first_letter = name[0]
17         if first_letter == letter:
18             count_boys = count_boys + 1
19     
20     for name in ssadata.girls.keys():
21         first_letter = name[0]
22         if first_letter == letter:
23             count_girls = count_girls + 1
24     
25     if count_boys == count_girls:
26         print(letter + ": the same number of boys names and girls names")
27     elif count_boys > count_girls:
28         print(letter + ": more boys names than girls names")
29     else:
30         print(letter + ": more girls names than boys names")
31
32

Benjamin Mako Hill || Want to submit a patch?