Use of the conditional “if” and “else”/”elif”

--Originally published at angelmendozas

This is an example from the challenge of the week I made with Carolina Vargas in class.

If is a condition, that states IF some parameters are accomplish then do something and is that IF doesn’t happen the you put ELSE, to do something ELSE… and if that ELSE doesn’t happen then you put another ELSE it’s just that now with ELIF because you can’t repeat the word ELSE.


Creating & Using own modules/libraries.

--Originally published at angelmendozas

To create and use you own modules you better code this:

import potato <- You can call you module whatever you want

potato.example (‘hello’) <-Then in parenthesis the output you want it to have

To install it in mac you use this command in the shell:

pip3 install <package>

and the you run your program on the shell and thats it.

It should print ‘Hello’


Libraries: Importing and using them

--Originally published at angelmendozas

To import a library f.e. math you literally use the command import and followed by the library you want in this case math:

Captura de pantalla 2016-09-07 a las 5.26.37 p.m..png

There a lots of Libraries/Dictionaries, you can even create your own ( it’s a lot of work obviously but sometimes necessary).

You can look up on google all the dictionaries that exist.

The results are these:

Captura de pantalla 2016-09-07 a las 5.27.10 p.m..png


Functions: Calling and Creating them

--Originally published at angelmendozas

To call a function you use the word “def” followed by the name you want your function to have, after naming your function, you need parameters and these parameters go inside parentheses() and at the end of these you are required to put a “:” then you decide which function to return to get the function you desire and then define your parameters of the functions like this:

Captura de pantalla 2016-09-03 a las 8.55.53 p.m..png

And so like this the console should give you 4.

A simple explanation of calling a creating a function is using the commands told before and then naming however you want your function to be called and which one you want in return, and finally give values to your functions.

Obviously there are more complex ways to use functions, but for now I will just explain the basic.


Basic Input in Python

--Originally published at angelmendozas

You use raw_input so the user can put an input and the question or thing you want him to fill

Captura de pantalla 2016-08-30 a las 12.07.42 p.m..png

In the shell the question is dropped and you write your name

Captura de pantalla 2016-08-30 a las 12.08.27 p.m..png

Just After you write your name, the shell prints what you told it to print, for example I programmed print(‘Your name is ‘ + x), because the result of x is your name and it prints this:

Captura de pantalla 2016-08-30 a las 12.08.50 p.m..png