Categoría: Sin categoría

Making life easier: Functions masteries 11, 12

Functions are easy ones, you just have to put the name of it, and the parameters, lets say.. the sum of three numbers

def sumas (w,x,y,z):
     suma = w+x+y+z
     print (sumas)

The w,x,y,z are the parameters, basicaly, when you call that function, you have to put those variables in that order

To call ir just type the name of the function, and then its parameters

sumas(1,3,4,2)

You can create them as complex as you wish, just remember the parameters!

There you have it! you’ve just created a function and called it!

There is an example of a little bit more complex:

definingcallingfunctions

That program will take two number, and will call a function named adds, which needs one parameter: X, to state the begining of the multiplications, and a Y, which will be the stop.

And also call a function named fact, which will get the factorial number, it just need the parameters X where x is the number you wish to take the factorial from.

And that is all!

The loops: For and while masteries 19, 20

whileforloops

With this program the conditional loop while and the loop with range of values are executed; te program basicaly asks for a number to make the factorial of it with the For, yet it does not allows you to type a float using the While

While

After the conditionals If, the conditional loop came in, they do everything inside them WHILE the condition is met

while

So

let f be a point, like the point of the float numbers

while (f in x):
       print («You see?»)
       x = input («Give me an integer»)

With these lines of code, you are making a restriction of value for X, that it can not store values with the point on it.

for () in range ()

for

This function is a combintation between the For loop, and the ranges. The for loop is basicaly say for a variable from the start value to the end one each n steps, it breaks when there are no more values. This is a little tricky one; first, you have to start with the for followed by a non-defined variable, then, that variable will ocuppy every number from x number including it to y number excluding it each z «steps» like this for e in range (x,y,z). {If you don’t put a z, it is 1}

We know a factorial number is that number multiplied by that number – 1 and so on, so we can recreate that with this for function

for e in range (1,x ):
fact = fact*(x-e)

which means that fact is going to take the value of fact times the number, represented with X minus the times the loop has run, represented with

e is going to take every value from X to 1 excluding 1 each 1 step, so if X is 5, e is going to be 5, 4, 3, 2, and 1dependig on which round it is.

And that is it!!

StraightOuttaSomewhere

The basics of programing: if, elif, else Masteries 15, 16, 17

elifelses

There is the code I made to put at work the conditionals. The program basicaly tells you if the number you typed is a float, an integer, a negative integer, or a negative float.

So first you ask for the number

x = input ( «Number» )

easy, then here comes the conditional.

if

if is called conditional, python will run everything «inside» the if, IF the condition inside the parenthesis is true

So first I will ask python if the number the user gave me is a negative float; if it has a «-» and a «.»

to do it, I store the point in a token name floatt, and the minus in a token named minus

minus = «-»                floatt = «.»

ifofelif

So    

if ( (floatt in x) and (minus in x)):
      print («It is a negative float»)

What you are typing is: IF the point storaged in FLOATT is inside the number stored in X, AND the minus storaged in MINUS is inside the number stored in X, then it is a negative float, and the program will say it to you.

elif

elifs

We already have the condition to a negatiuve float, but we don’t have he conditions of float or negative.

But we can’t put another if because the program will run the first condition, then the second one, and so on, so a negative float is a negative and a float, that’s why elif is so useful.

You can ask, if the IF conditions didn’t met, another condition with elif.

So

elif (floatt in x):
       print  ( «It is a float» )

elif (minus in x):
       print ( «It is a negative number»)

You are asking only when the first coindition don’t met if FLOATT  is inside of X, if not, then you ask if MINUS is inside X.

else

else

Finally, if none of the previus conditions were met, ELSE finally gets into scene, then it is a integer,

So

else:
      print ( «It is an integer» )

An that is pretty much all! You know how to use if, elif, else conditionals!

It’s like batman beating a giant hand

About WSQ04

Here is little bout me:

I am studying Computational Systems Engineer, and it is because I really love programming;I love spent my time doing something that at the end will be unnecessary because there was a simplier way; I love to break my head solving problems, but only programming, and yes, I am sure of it.

I think that my hero, well in comics my favorite «hero» is Deadpool, but in real life, i think it will be Akon, because depite being famous and rich, he is helping african people to fave solar energy in their communities, without earning money, and withouth telling everyone «Hey! I am helping them! looki at me!»

I used to play the drums, mostly metal, before get into the tec, and right now… well let just say I don’t have much time since I entered to the football team, oh yeah, I am on the football team of Borregos GDA as offensive linemen

My favorite author of music is probably Kendrick Lamar, of books it would be García Márquez, a genius.

Here are my favorite five songs:

The great sum WSQ07

So I was asked to do a really simple action, to sum every integer from one number to another. I wanted to keep this simple, so I just add a single one extra action tha was if the first number is bigger than the second one, ask the user to put the second one as a bigger number.

So basicly I used the for e in rage ( 1st number, 2nd number plus 1) to stablish the range and then add to a variable the variable plus e, and it runs by itself:

sums

sorry for the short post, here is a potato

Damn blood experiments, Why not water?! WSQ05

So some psychopatic scientist named (Farengeith… farenheight… Farentsomething) had the brilliant idea -note sarcasm- to experiment boiling blood, yup, he used human blood to state a scale for temperature; was not easier water? please? like Kalvin or Celcius, well, no problem.

So I was asked to do a program that convert Farensomething ° to Celcius °, pretty simple isn’t it? Well, I am a stubburn,

stubborn

so I complicate my life with 3 key points:

  • Celcius to Farensomething and vice versa according to the choice of the user
  • ONLY numbers
  • GIve the user the posibility to start again

I based on another program I’ve done for the second and last key point:

https://charliegdrummer.wordpress.com/2015/09/01/first-code-of-the-semester-wsq03/choice while

The first part, Celcius-Farensomething and viceversa was pretty easy:

tempeture

Toooo easy

First code of the semester WSQ03

Well, the WSQ03 was basicaly do a program that will recieve 2 numbers, and sum, rest, multiply, and divide them; very basic, real quick, but since I am very stubborn, I wantdel blog wordpress sueschefftruthed to create a software that does not allow you to type anything but integers. Obviously, this was not going to be a 5 minute task, so here we go..

So the two key points where I wanted to base my program were:

  • Just input integers, except for the name and other decitions
  • It gives you the choice to start the program again

So for the first part, the one with just integers, I first had to figure out how will the computer detect it is a float, and since every input in python is a string, I couldn’t just ask the type as type(x), so I used the «in» function to chek if in any of the variable was a «.» stored in  «e»:

in for float

Then, the hardest part came in, figure out how the banana i was going to tell the program the input was not a string, little problem, all inputs are strings!, so I asked aid from Bauer, and he pointed me in the right direction with this python webpage: https://docs.python.org/2/tutorial/errors.html

And here is the part:

while try number

And the last key point, the ability to reload, was pretty easy. I just used a variable named choice and asigned a lowercased string that if it is yes, the whole problem runs againwith a while:

choice while

The rest, was pretty much a piece of pizza:

numbers

And that’s it!

Flipping the world WSQ02

Flipped Learning

The «Flipped Learning» is basicaly the scream of millions of students for indivualization. Instead of the traditional – cof cof boring – system in which the professor gives the lecture to the students, flipped learning is the student taking the «lecture» via internet, and advancing at its rythm, then, the student asks the teacher for help in his/her doubts.

This new way of learning is oriented to the idea that every student has his own abilities, and that is unfair to evaluate students as if they were all the same.

*Individual learning
*Classes for doubst and coaching

Workspace WSQ01

-Open laptop
-Open chrome
-San google
-Type Python
-Enter python.org
-Screw you shoulder

11846392_10207475048424643_432202611_n

-Clic on download

-Download the installer of python 3.something

-Wait to download

-Open youtube

-See a astley-avicci mashup

-Waste time watching videos

-Realize download is over

-Install python

Sin título

-Finish

-Return to youtube