Library

--Originally published at Hackerman's house

A library is a built-in module that can be used to solve several problems. Once python is installed it includes a series of standard libraries such as math that can be used to solve mathematical problemas or generally just to work better with numbers. There is also the time library to count the time. You can find more information about it here.

https://docs.python.org/3/library/

In this example we’ll be importing the “math” librarie to calcule the area of a circle, the radius will be given by the user and the program will substitute this number in a formula

Import a librarie is simple, the syntax is this:

import name_of_the_library

And the functions included in every library are different, these functions can be find in the link above.

The functions of math that we’ll be using is the pi value.

libraries

The “try” and “except” are used to determine if the input given by the user is a number. The radius is given by the user and the area has a simple formula PI times radius square. That is why we needed the math module.

Here is how the program works.

libraries2

Thanks for reading me.

giphy-5


Functions in python

--Originally published at Hackerman's house

A function is a structuring element that groups some lanes of code that can be utilized many times in the program. Is basically defining a formula to then just put the name of the formula, and the program will run it without the need of writing it again.

The syntax looks like this.

def name-of-the-function(Parameters):

Statements

The statements determine what your function will do.

To call a function you just need to put the name of a function previously defined.

name-of-the-function()

This is a really simple example about how to define a function and then call it two times. What this would do is run the same function two times. It is important to note that this function has no parameters.

function

And this is how the program works.

function2

Besides this really simple program I created another that actually uses parameters.

function4

This program executes a sum of the two parameters given.

And here it is how it works.

function5

Thanks for reading me.


You will enjoy WHILE you are here.

--Originally published at Hackerman's house

The while loop is a function that repeats a section of the code. This section will be repeated as long as a condition is repeated.

The syntax used is:

while condition:

Section of the code that will be repeated.

The code I created is used to count from 0 seconds to 15 seconds, I also import a python library in a pretty basic way, but we will see that mastery topic in depth in another blog post. As long as the variable in the program is less than 15, the variable will be printed with a 1 second delay. When the condition no longer is fulfilled you can do that the program does something else with the ELSE function.

While loop

Here is how the actual programm works.

While loop result

And this is the final result.

While loop result

I hope this blog was useful for you.

giphy (4)


IF you are awesome read this, ELSE go away.

--Originally published at Hackerman's house

I created an awesome program that uses the function IF and the function ELSE. It can be used to determine if one input is bigger than other. These inputs are related to the cost of a product, and the money a person can expend.

giphy (3)

There are 2 ways of using the functions if and else. In separate lines, and in the same line. Both ways are used in my program, each one show one sentence as an answer to the user.

If, else

Here is how the program works if the user has more money than the cost of the product.

IF yes

Here is how the program looks if the user doesn’t have enough money to buy the product.

IF no

I learn about this function using the Basic Python 3 course at Lynda.com

Thank you for reading me.

giphy (4)

 


The Zen of Python

--Originally published at Hackerman's house

giphy (2)

These are the guiding principles of the Python language. These are useful to understand the pilosophy of the language and to understand easily how Python works.

These can be found in the official python site at the following link: https://www.python.org/dev/peps/pep-0020/ Zen

It is useful to know your priorities when you are programming.


Commenting about seafood.

--Originally published at First Programming Steps

hackerman

In this file I practice the use of comments in one line, and the multiline comments. The one line comments are after a # everything after this sign would not count for programming, and it only will be seen in the code. These commments are used to remind the programmer what his program is suposed to do in each part of the code.

The multiline comments are between ”’ these are used in a similar way as the other comments, but you are able to write longer comments.

Comment

When your program the comments won’t be shown in the screen. These are only shown in the IDE. In the next image you can see how the comments doesn’t appear when I run the program.

Comment result

Thanks for reading this post.

giphy