Let’s use a library

Hello, buddies! Today we’ll learn to use the factorial function son we don’t crash our brain trying to figure out how to make a factorial calculator by ourselves with a loop like in WSQ09.

There’s a magic bunch of functions already settled on python that you can use. There’s no reason for you to create a solution for a problem if you can use a module.

Here’s my example:

fact1

Instead of doing the while loop, you can import the “math” library and the command to get the factorial is math.factorial(name-of-the-variable). Like in the example above. You can check this webpage to know more about this topic.

Have a nice day!!!

 

Partial Exam #1

Hey there! On this blogpost I’ll ulpoad the guide I did to study for my partial exam.

I read “Beginning Python”by Peter C. Norton, Salez Samuel, Dave Aitel, Eric Foster-Johnson, Leonard Richardson, Jason Diamond, Althea Parker and Michael Roberts.

I’ve been using this book during all the partial and it’s been really useful.

Well, here are my answers:

  • How do we create comments and why?

With the # symbol. We write them through the program to indicate it’s development or just to write notes. Sometimes they’re used to skip parts of the code that are no longer needed.

  • Explain the basic types and why there are different ones.

Data Types are categories for things within a program with which the program will work. There are different ones because you won’t use the same kind of objects every time you make a code. For example, if you need a number with a decimal part you’ll use a float, if you need an integer number, you’ll use the “int” type.  After a thing has a type, the program and the programmer knows what to do with it.

  • How do we do basic input and output (text)?

Most of the times is necessary to assign a variable to each input so we can manipulate the information in the code. The “input” syntax looks like this:

X= input (“text”)

I always output information with the “print” command. The syntax is this:
print (“text”). If you’re adding variables to your output sentence, the syntax will be (“text” , variablenumber, “text”)

  • How do you call functions?

When we have a function already defined, we assign a variable to it, and to call it, we just write: print (variable assigned) and our function will be executed.

https://www.youtube.com/watch?v=OaYDfOCsKtE min 5:00

Quizzes :)

This blogpost will be dedicated to explain the quizzes that we made during the first partial.

QUIZ #1

The first quiz had two exercises: To obtain the volume of a cylinder with the values that the user wanted and exactly the same exercise that we did in “Fun with numbers (WSQ03)”

The first code is:quiz1.png

It’s really easy. We just need to ask the user for the radius and the height. Remember that the formula to get the volume of a cylinder is πr^2h. We use the “float” type of number because we don’t know if the user will type an integer or a number with a decimal part.

At the end, the result is printed.

Let’s explain the second exercise.

It’s exactly the same exercise than “Fun with numbers (WSQ03)”. The only difference is that all the results are printed at the same time.

quiz13

Here are my codes: Cylinder SumOfNumbers

Quiz #2

 

Factorial Calculator (WSQ09)

This code will be about creating a factorial calculator and we’ll keep practicing with the “while” loop.

Before I show you how to do the program, let’s review what a factorial is. According to this webpage, isthe product of a given positive integer multiplied by alllesser positive integers: The quantity four factorial (4!) = 4321 =24. Symbol: n!, where n is the given integer.”

Now we’re ready to start programming.

factorial1

First, I’ll make the main code. It’ll make the calculator’s work. As always, we ask the user for the number with an input. Then we convert the variable to an integer so the program is able to use it. The counter is designed with the value “1” just like the R variable.

Is necessary to do this before the while loop because if we just start using variables without specify their initial value, Python won’t recognize them and the program won’t run.

What the loop does is simple, it just multiplies the consecutive numbers from 1 to the number that the user gave us. For that reason the “cont” variable increments one unit each time the code runs. The loop will end when the counter gets bigger than the variable that the user typed.

Up to here, when we execute the program,  the terminal window will show this:

factorial2

And NOOOOW we’ll insert another loop to ask the user if he/she would like to use the program again.

factorial3

You can notice that I added another variable with the “yes” assignation. This means that WHILE the answer to the question in line 11 is “yes” the program will keep running. If the user types something different, the loop will end, and the word “thanks” will be printed.

You can be aware that the

factorial4.png

Continue reading “Factorial Calculator (WSQ09)”

Sum of numbers (WSQ07)

On this blog I’ll develop a code that asks the user a range of numbers and the program will return the sum of all numbers of that range.

To get started, we need to ask the user for the range of numbers with an input:

sum1

After that, is necessary to convert the inputs to integer numbers so our program can run without problems. Every number in python needs to have a type of number, it depends of what you need to do. For this program, I’ll use integers because this program does not need something more elaborated.

We also need a mathematical counter, I’ll explain later why. For now, we’ll give it the value of zero.

sum2

Then, a loop is needed to do the whole mathematical process, because the program will sum each number of the range consecutively.

While programming the loop, you need to be careful so you don’t code things unnecesarily. (Like I did) All the comments are the lines that wasn’t needed but I wrote at first, until the teacher helped me out to optimize the code.

sum3.png

The logic of the program is simple, the “cont” variable will sum the numbers of the range and the line #10 is the one that will increment the value of each  number of the serie as it advances.

Finally, we just print the result with the syntax that we already know. sum4

That’s it! We’re done with it!.

As always, I uploaded my code so you can check it.

Pick a number (WSQ06)

This homework is really fun, because I need to create a game, so the user should guess which number the program did choose.

I didn’t know how to print/choose a random number, this website helped me out. The variable for the random number will be “x”

Alright, the range that I need is from 1 to 100. While proving the code, I’ll print the random number, but I’ll erase line 3 when I end up the homework. pick a number 01

Then I need the user to guess my number, so I enter an input. And of course I assign it a variable, “y”.

pick a number 02

After that, we start with the “if” sentences.

pick a number 03

As we want our user to guess, we need to give him/her some clues. If he/she typed a lower or higher number, the program should print which is the problem.

Up to here, the result is this:

pick a number 04

Now I’ll say the user how many times he/she needed to guess the right number, and I’ll also comment line 3.

pick

Aaand there we go… 😀 Here’s my code, you can download it if you need/want to.

See ya..!

 

WSQ02

Hey there! Apparently I didn’t do the easiest homework of the course: to print “Hello World”. So this blog will be about that.

First of all, we open the editor and the terminal window.

wsq02

And I’ll save my file as “hello1.py”

wsq0201

Then, I use the “print” label, followed by the ‘Hello world’ sentence. And I run it in my python program.

Be sure your text has the correct syntax. (“text”)

That’s all for today. Have a nice day!

(WSQ04)

pupitres-tec
http://blogdeducacion.com/2015/07/21/mobiliario-escolar-innovador/

Showing the Differences between a Traditional and a Flipped Classroom

It’s amazing the engagement that the teacher has in his classes, I mean, most of the classes that I have had are made in the traditional way, and after watching this video I realized that I haven’t learnt enough and it would have been much more productive if the classes were flipped. There’s a lot to work on in mexican education model. Teachers and students need to WANT to do the work, not just because “I need the grade” or “I need to feed my family”. We need to do everything with passion and engagement.

An A+ student regrets his grades

This post makes me think about what is really worthed during our time spent at college. Makes me wonder if all my 90 grades were actually 90 in my learning process. I need to change several things by my own if I want to start learning more than memorizing.

Suggestion: The Finland phenomenom

On this video, the finnish education developers show the effectiveness of their system and why it works. Finnish education is the best around the world, according to several rankings. The documentary is very interesting, check it out.

Temperature (WSQ05)

This homework is about converting Fahrenheit degrees to Celsius. The deal is that we need to ask the user for the temperature in Fahrenheit, and the code does the rest to convert that quantity to Celsius.

As I need the user to give me the number, I enter an input in my program, and I assign a variable to it. I will assing the variable “f”

temperature 01 - copia

To do the math process, we need to create another variable, so then a result can be printed.

temperature 01

My new variable is “c”, followed by the operation that will convert the Fahrenheit degrees to Celsius. I should be careful in this part because at the beginning I wasn’t writing the right syntax, so I had to try many times to get the right result, my advice is: be careful with the parentheses.

The formula is  C = 5 ∗ (F − 32)/9 we just need to transform that in a code. I’m telling the program that I just need the integer result with the “int” label, before the whole sentence.
Then I need my “f” variable. Let’s convert all our numbers to integers, I won’t use any float today, so I’m converting my “f” variable to an integer “int”.

temperature 01 - copia (2)

Let’s print the result. To include the variables in the sentence, we must close the (“), type a (,) and then the variable. Like in the picture above.

temperature 01 - copia (2)

The rest is easy. It’s necessary to indicate if the temperature that the user give us would make the water boil, freexe or none of them. We get that with the “if” label.

In the first “if” sentence, I needed to indicate the “range” in which the water is neither boiling nor freezing. We print the sentence that will indicate the result to our user. NOTE: you should type

temperature 02

Continue reading “Temperature (WSQ05)”

Fun With Numbers (WSQ03)

The goal is to create a program that asks the user for two numbers and Python will show the difference between them.

First of all, we need to know the keywords that we’ll use. I write this at the beginning because I had no freaking idea about which labels would make what I wanted:

print: Print is the keyword that will order Python to write an specific sentence on the editor, so the user can understand what we want him/her to do. The syntax should be lije this example: print (“Text that you want to print”)

input: This label will keep the information that we’re asking for. The syntax will be like this: input (“What we’re asking the user to write”)

float: For this program, “float” helped me to make the difference between the inputs. I’ll show you what I’m talking about when I show you my program.

The difference of the two numbers.

Ok, now, if we want to make the difference of two numbers, we need to ask for them, but also to assign a variable to each one, so then we can make the operations.

To get that, we assign a different variable to each input, like in the image below

fwn1 - copia

To get the result, we just need to add another variable and assign it the value of the difference.

But be careful, THIS is why you need the floats.

fwn1

If you just type (+) the program will print the first number followed by the second one, but if you write “float” before each one, you’ll get thisfwn3

I figured out that a float was needed thanks to this post.

This YouTube video was helpful too.

The product of the two numbers

We keep going and make exactly the same process, but this time, instead (-), we type

fwn4
fwn5 - copia
fwn6

Continue reading “Fun With Numbers (WSQ03)”