Lab 9 Problems

The exercises for Lab 9 are listed below. If you did not attend lab you will need to email Allison your solutions. If email doesn't allow you to send them as attachments, upload them to Google Drive and send Allison a link.

  1. print_entire_file

    Write a function named print_entire_file that prompts the user for a file name and prints the contents of that file to the console as output. You may assume that the file exists. For example, if the file example.txt contains the following input data:

    hello  how    are you
    1 2 3 4
    I am fine
    

    Then the following would be an example dialogue of your function:

    Type a file name: example.txt
    hello  how    are you
    1 2 3 4
    I am fine
    
  2. count_coins

    Write a function named count_coins that accepts a file name as a parameter. The files' contents is a series of pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be "pennies" (1 cent each), "nickels" (5 cents each), "dimes" (10 cents each), or "quarters" (25 cents each). Add up the cash values of all the coins and print the total money. For example, if the input file coins.txt contains the following text:

    3 pennies 2 quarters 1 pennies 23 nickels 4 dimes
    

    The call of count_coins("coins.txt") should produce the following output:

    4 pennies
    23 nickels
    4 dimes
    2 quarters
    Total money: $2.09
    

    You may assume that the file contains at least 1 pair of tokens. You may also assume that the input is valid; that the input has an even number of tokens, that every other token is an integer, and that the others are valid coin types.

  3. vowel_count

    Write a function named vowel_count that accepts a string as a parameter and returns a list of integers representing the counts of each vowel in the string. The list returned by your function should hold 5 elements: the first is the count of As, the second is the count of Es, the third Is, the fourth Os, and the fifth Us. Assume that the string contains no uppercase letters.

    For example, the call vowel_count("i think, therefore i am") should return the list [1, 3, 3, 1, 0].

    You can loop through a string and access each character exactly the same way you can loop through a list and access each element. Find the string length with len and access individual letters with [].

  4. mode

    Write a function named mode that accepts a list of integers as its parameter and returns the mode of the numbers in the list. The mode is the number that appears most often in the list. To figure out which number appears most often, count the occurrences of each number. Store your counts in a list. Store the count of 0s at index 0, the count of 1s at index 1, etc. Assume that the numbers in the list are between 0 and 99 inclusive.

    For example, the mode of [5, 2, 4, 17, 55, 4, 3, 26, 18, 4, 2, 17] is 4, and the mode of [42, 25, 25, 37, 1, 97, 1, 2, 7, 42, 3, 25, 89, 15, 10, 29, 27] is 25.

  5. GUIs

    Create a graphical user interface with 3 buttons and a label. Display a message in the label when one button is pressed. Clear all text from the label when the second button is pressed. Display a different message when the third button is pressed

Upcoming Due Dates