# WSQ13 – Cars

## What To Do

File input/output is our access to permanent stores of data that last beyond the run time of our application.

Write a program that opens and reads the file 93cars.dat.txt and produces the following data:

• average gas mileage in city (City MPG)
• average gas mileage on highway (Highway MPG)
• average midrange price of the vehicles in the set.

You can find the data set at the following link from the Journal of Statistics Education.

## 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 #WSQ13 on your post so our blog hub picks that up.

And of course, leave any questions here as well as asking those questions in our Slack channel so we all see your question posted there.

# WSQ12 – Estimating e

## What To Do

In this assignment you will estimate the mathematical constant e. You should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

You will want to use the infinite series to calculate the value, stopping when the accuracy is reached (previous and current calculation are the same at the specified accuracy).

## 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 #WSQ12 on your post so our blog hub picks that up.

And of course, leave any questions here as well as asking those questions in our Slack channel so we all see your question posted there.

# WSQ11 – Go Bananas

## What To Do

Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana”  (or “BANANA” ) is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.

## 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 #WSQ11 on your post so our blog hub picks that up.

And of course, leave any questions here as well as asking those questions in our Slack channel so we all see your question posted there.

# WSQ10 – Babylonian Method

## Background

In this assignment you will write a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find.

## What to Do

The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.

## 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 #WSQ10 on your post so our blog hub picks that up.

And of course, leave any questions here as well as asking those questions in our Slack channel so we all see your question posted there.

# WSQ09 – Multipart Data and Files

So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). You will want to look at how to use and return a tuple from a function and how to open and read text files line by line.

## What To Submit

As always a blog post, tag with #WSQ09 and perhaps put your code up on GitHub. Ask for help or input via Slack in our #tc1014gda channel.

Feature Image Credit

# WSQ08 – Yo Soy 196

## Background

Lychrel numbers are natural numbers that do not form a palindrome after successive additions to their inverse. See details on Wikipedia: http://en.wikipedia.org/wiki/Lychrel_number

## What to Do

Your job is to create a program that asks the user for two pieces of data:

• The lower bound of the sequence
• The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”

## Details

The report must show:
• The range of numbers analysed (lower to upper bound)
• The number of natural palindromes (no addition to inverse needed)
• The number of non-Lycherels encountered (become palindromes)
• The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

This is easier in Python but if you are curious and want to try this in C++ (Java would be similar), to get this working well, you will need support for Big Integers. You can base your solution off my codebase on GitHub. Unzip all of the files in a directory and use the command “make” to compile. Run the executable.

## 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 #WSQ08  on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

And of course, leave any questions here as well as asking those questions on our Slack in the #TC1014gda channel so we all see your question posted there.

# WSQ07 – Lists

## What to Do

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

## Details

For the Python group, you want to be using Lists. For the C++ group you can do this with arrays or Vectors, but you will need to know eventually how to do both.

Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

## 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 #WSQ07 on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC101 so we all see your question posted there.

# WSQ06 – Factorial Calculator

## What to Do

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

## Details

For the Python group, resist the urge to call math.factorial(n). Yes that would solve the problem but what would we do if there was no math.factorial() and we had no internet to find someone’s solution?

There are two basic approaches: a loop with an accumulator of the multiplication and a recursive solution. Choose one and implement that. Once that is done, try the other way.

If you used a while loop for the solution with a loop, try structuring this with a for loop (or vice-versa).

## 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 #WSQ06 on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1014 so we all see your question posted there.

# WSQ 05 – On To Functions

## What to Do

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

## 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 #WSQ05 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1014 so we all see your question posted there.

# WSQ04 – Sum of Numbers (Week 05)

## What to Do

https://www.flickr.com/photos/wisamallami/2478134485/

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

Notice our sum starts with zero (why?) and then we add each number in the range provided by the user. Just for fun, what is the mathematical formula to do this calculation?

## Example Run

We will calculate the sum of integers in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55

## Thoughts

How would you change your program to handle the user giving you the upper and lower bound in the wrong order? Or perhaps some other “user input error”?

## 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 #WSQ04 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

You may want to check how to get started on GitHub now, here is a good article to start with: http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1014 and #WSQ04 so we all see your question posted there.