Homework 4: Counting


Two problems:

  1. Counting Nines (nines.py, nines-tests.txt): Computers count fast.

    Read a positive integer input n, and count the number of occurrences of the digit '9' in the decimal representation of all the numbers between 1 and n inclusive. Print that number.

    For example:

        Number? 19

    Another example:

        Number? 300

    Hint: Probably the easiest way to do this is to convert each number from 1 to n to a string, and then count the number of "9" characters in that string.

  2. Counting Vowels (vowels.py, vowels-tests.txt): What if you had to buy all your vowels?

    Open a file called "input.txt" and count the number of vowels in the file. Print that number. For our purposes, the vowels are just "a", "e", "i", "o" and "u". Remember to count both uppercase and lowercase vowels.

    For example, if you download http://po8.org/bart/gettysburg-address.txt and count its vowels, you should find 457.

Your assignment is to write and test a program that meets each specification. Submit each program as a text file with the name given in the problem. Submit test runs of each problem as a text file with the name given in the problem. Also include a text file called "writeup.txt" containing a writeup that contains a brief note about what you did, what problems you had, and what you learned.