WSQ09 – Factorial Calculator

What to Do

creative commons licensed (BY-SA) flickr photo by ▓▒░ TORLEY ░▒▓: http://flickr.com/photos/torley/3505324528
creative commons licensed (BY-SA) flickr photo by ▓▒░ TORLEY ░▒▓: http://flickr.com/photos/torley/3505324528

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 WSQ09 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.

WSQ08 – On To Functions

What to Do

creative commons licensed (BY) flickr photo by kevin dooley: http://flickr.com/photos/pagedooley/8435953365
creative commons licensed (BY) flickr photo by kevin dooley: http://flickr.com/photos/pagedooley/8435953365

You will go back and do WSQ03 – 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 WSQ08 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.

WSQ07 – Sum of Numbers

What to Do

https://www.flickr.com/photos/wisamallami/2478134485/
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 WSQ07 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 #TC101 so we all see your question posted there.

Mondays – Week Three

Quiz Time

We will do a quiz at the end of the week to give you a formative assessment to see where you are. Relax, this is not “worth points” but focused on giving you feedback.

flickr photo by Harald Groven http://flickr.com/photos/kongharald/15038239390 shared under a Creative Commons (BY-SA) license
flickr photo by Harald Groven http://flickr.com/photos/kongharald/15038239390 shared under a Creative Commons (BY-SA) license

Video Info

My regular Monday morning video for your viewing enjoyment:

 

WSQ06 – Pick a Number

What to Do

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

Example Run

I have a number chosen between 1 and 100.
Please guess a number between 1 and 100:  50
I’m sorry but 50 is too high, try again: 25
I’m sorry but 25 is too low, try again: 42
You got it! The right answer is indeed 42.
You made 3 guesses to get the right number.

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 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 #TC101 so we all see your question posted there.

WSQ05 – Temperature

What to Do

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given. Your output might look like the following

Example Run

What is the temperature in Fahrenheit? 100

A temperature of 100 degrees Fahrenheit is 37 in Celsius

Water does not boil at this temperature (under typical conditions).

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.

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.