initial version of answers for babynames exercises based on daniel epstien's code
[babynames_answers] / answer_9.py
1 # 9. Take a prefix as input and print the number of boys and girls with that
2 #    prefix. (i.e., "m" would list babies whose names start with "m" and "ma"
3 #    would list babies whose names start with "ma", etc).
4
5 import ssadata
6
7 prefix = input("Input a prefix: ")
8
9 boysNamesWithPrefix = 0
10 for boysName in ssadata.boys.keys():
11     if boysName.startswith(prefix):
12         boysNamesWithPrefix = boysNamesWithPrefix + 1
13
14 print("There are " + str(boysNamesWithPrefix) + " boys names that start with " + prefix + ".")
15
16 girlsNamesWithPrefix = 0
17 for girlsName in ssadata.girls.keys():
18     if girlsName.startswith(prefix):
19         girlsNamesWithPrefix = girlsNamesWithPrefix + 1
20
21 print("There are " + str(girlsNamesWithPrefix) + " girls names that start with " + prefix + ".")

Benjamin Mako Hill || Want to submit a patch?