Gone Bananas for Files

Files and bananas.

Question 1

Create a function called readNumbersFromFile that receives as a parameter a string with the name of a file (located in the same directory) of numbers. The file has a number on each line (assume all integers).

Here is a link to an example file for you http://kenscourses.com/tc101winter2015/wp-content/uploads/2015/01/random_numbers.txt

The function will open the file, read the values and then print (that is right, this function returns no values) the following:

  • The total of the values
  • The number of values (same as number of lines btw)
  • The arithmetic mean (average) of the values
  • The standard deviation of the values.

Question 2

Write a function called check_banana that receives a single parameter of type string that is the name of a file in the same directory as the program. The function opens that file of text and counts the number of times that the string “banana” appears. For full marks it should ignore case (so count Banana, BANANA, bAnAnA regardless of mix of upper and lower case characters).

Hint#2, you will want to be able convert strings to lower case:


  • 10 points if submitted before midnight on April 28.
  • 9 points if submitted before midnight April 29
  • 8 points if submitted before midnight April 30
  • etc (1 point less for each day later)

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #QUIZ11 on your post so our blog hub picks that up.

You MUST include your code as links to GitHub.



CC BY 4.0 Quiz#11 by Ken Bauer is licensed under a Creative Commons Attribution 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.