#WSQ10 – Lists

All right people, here’s what we need 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.

Easy code, let me show you:

WSQ10

Don’t forget to import “statistics”, so you can not call stdev and pstdev commands.

Let’s keep moving.

#WSQ09 – Factorial Calculator

Hey people, it’s been such a long time since my last post, but, I’m back.

As always, here’s what we need 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).

So, let’s begin:

WSQ09

Not a difficult code, but it’s a little long, if you have any question about my code, just ask below in the comments section.

Let’s move.

#Quiz01

Here are my solutions to the first quizz of this course.

You can see the quizz tasks here: Quizz #01

Let’s do it:

Program #1:

FullProg1

Don’t forget to import math library and this time the inputs are float numbers (really easy task).

Program #2:

FullProg2

We’ve done this program like a two times, way too clear for everyone. (Check WSQ03 and WSQ07 if you didn’t see this yet).

Program #3:

FullProg3

Don’t forget the float inputs, not integers like we always do.

#WSQ08 – On To Functions

Functions. Pretty easy task. Here’s the list:

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

Basically, we need to make every operation of WSQ03 to be converted into a function.

Let’s begin:

FullniceWSQ08

 

This time, I’m not going to give you a lot of explanations, this is a pretty simple task. Ask for two integers (a,b), then, send the parameters (a,b) to every function (don’t forget to type “def” when you’re going to name a function or it will not work).

At last, just call every function, because functions aren’t going to work by themselves until you call them.

We run the program:

RUNWSQ08

And we’re done. Kind of too easy, huh?

#WSQ07 – Sum of Numbers

Ok, we’re doing it really fine, but now, it’s time to combine while loops with conditionals.

(I needed help in this task, so my friend David García (he finished this course already last semester, here’s his wordpress blog link: David’s Blog) helped me to finish this task.

Also my friend Héctor Bueno helped me, here’s his blog: Héctor’s Blog.

Here’s what we have to do:

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

Let’s begin:

WWSQ07

We have to open a while loop that will keep repeating until the program reaches the range we defined for the program.

aWSQ07

The “ValueError” works for people who tried to insert a variable instead of a integer, and also, breaks the loop.

The first condition (“if”) works for people who type a more bigger number in the lower bound than in the higher bound, making the range imposible to calculate. This condition also breaks up the loop too.

The second condition (“elif”) works for people who type the same number as lower and higher bound, making the range imposible to calculate too. This conditions (yes, again) breaks up the loop.

The third condition (“else”) (the good one) works for people who type things right and includes numbers from the lower bound number (lb) to higher bound number (hb) (+1 is for the higher bound number to be included in the range). The loop repeats until it reaches the higher bound number making

RUNWSQ07
FullWSQ07

Continue reading “#WSQ07 – Sum of Numbers”

#WSQ06 – Pick a Number

Time for “While” loops, here’s what we need to do:

  • Write a program that picks a random integer in the range of 1 to 100.
  • 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.

Let’s start:

1WSQ06

You strictly need to import the random library, don’t forget the “import random” sentence or your program isn’t going to work.

Our random number (“r”) will be composed by our number (num), multiplied by the random number the program generates, plus one.

2WSQ06

Time for the real thing. You just have to open a while loop that consists on repeating the same action as long as our guessing number (num) reaches equality with our random number (r).

When num = r the “print” line at the bottom will run, telling us that we guessed the number.

Let’s run the program:

RunWSQ06

Here’s the full program:

FullWSQ06

 

Not the most easiest thing in the world, but nothing we can’t do.

#WSQ05 – Temperature

Now, we’re going to learn how to use conditionals. This task requests the following steps:

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

So, let’s do it:

TempWSQ05

Ask for the temperature (“F”).

CWSQ05

Our second variable (“C”) is the formula to convert from Fahrenheit degrees to Celsius degrees, so just include your variable in the formula and you’re good.

#Tip: Use “//” on divison for evading float numbers like 35.77777777777.

PWSQ05

Do the first simple print, showing the two variables you got.

IWSQ05

Time of conditionals (“if” in this case); the first one actually applies for every celsius temperature that is under 100 celsius degrees, if this condition applies, a sentence saying that water will not boil at the temperature we typed will be printed. So, in the second one, for every temperature that passes 100 celsius degrees, a sentence saying that water will boil at the temperature we typed will be printed.

And that’s it, we just have to run the program:

RunWSQ05

There’s the full program:

FullWSQ05

We’re doing good, let’s keep moving.

#WSQ03 – Fun With Numbers

Ok, you’re doing it fine, but things are not that easier, so we’re going to increase the level according to how we advance in this course.

In this program we’re required to:

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

Fine, seems not too easy, but it is, so, we’re going to start with the integers you have to ask for your program:

IntegersWSQ03

The next step is what we saw last WSQ, the “prints”: (Don’t forget that the task asks us for an integer division so the operation command for an integer division is // not /, so becareful).
PrintsWSQ03

And that’s it, we’re almost done. By last, we have to run our code to prove it works:

RunWSQ03

 

I’ll leave you the full code here:

FullWSQ03

Pretty easy, right? But we have to continue, let’s keep going.