Sorry, Ken says that I need more posts

--Originally published at Welcome to the Heaven

The last post was about the conditionals “if” and “elif”, and if you are smart you can see that in the post I forget one conditional that is as important as “if” and that is the conditional “else“.

The two last make that the program make a specific instructions if the answer is the same as the statement. So why is else different?

Else is the essential part of the conditionals that not is the most important but never can lack. Else makes that if the answer that the program receives is not the same as the statements of the conditionals, the program don’t stop and can continue running with the code inside else

I know that you want an example:

screen-shot-2016-10-28-at-3-54-51-pm


“If” I had 17 years old…

--Originally published at Welcome to the Heaven

Do you want to learn about the conditionals  “if” and “elif” you’re in the right place. Normally we use this kind of conditionals to give an instruction to the program what it would do if one answer is like the statement.

if” and “elif” are the same thing, the unique differences is that “if” is above the “elif” when you’re programming, “if” is the first conditional that you write in your program and after this the next conditionals are with “elif“.

Example:screen-shot-2016-10-28-at-3-29-15-pmscreen-shot-2016-10-28-at-3-30-42-pm

if you want more examples you can see my others blog, almost in all I have examples with code and that code has conditionals, so…

WHAT ARE YOU WAITING TO SEE MY OTHER POSTS?


Loops loops loops

--Originally published at Welcome to the Heaven

Okay in this post I am going to show you how it loop “while” works. I have a old post that has another example of the loop “while” if you want to see it, click in more loops or for a different example in frutilupis.

The loop “while” is a kind of loop that allows repeat all the instructions of the code that are inside it. The way to work of this loop is that when the conditional is true, all the instructions can run.

Let’s see an example:

screen-shot-2016-10-28-at-2-35-13-pm

As you can see if the answer of the input “shoot” is yes you get in in the loop and when you are inside it, the program show you a message and a question if you want to stay inside or go out so if you say “yes” all the time, the loop will never end.

screen-shot-2016-10-28-at-2-40-34-pm
As the program runs

 


Creating and using your own modules/libraries

--Originally published at Welcome to the Heaven

Create our own modules/libraries is pretty helpful when we are programming to have an organized code. We can create it with a file .py, that we can call in a program to have a code clear.

If you have some questions about modules and libraries you can see my last post.

I will show you an example of how to make it possible…

screen-shot-2016-10-27-at-11-17-13-pm

In the first file(blog.py) we save the function that we’ll use in our main program, to have it more organized and we only import the module and assign values to the variables.

So now you can make your own modules/libraries and make more organized and clean your code.

screen-shot-2016-10-27-at-11-22-45-pm


Importing and using modules/libraries

--Originally published at Welcome to the Heaven

The modules and libraries are this beautiful things that you will find when you are programming. These ones help us when we are programing and we need a function that already exists. Like when you need that your program make a random action the only thing that you need to do is import the library random:

screen-shot-2016-10-27-at-1-59-11-pmAs you can see we use one specific function from de library random, that actually have a lot, if you want to se more: Random library

We can have the same result of a module as a library, but the difference between these is that a module is a file that has a lot of functions inside it and is save like a .py file, for other side a library already exist and you only import when you need to use it. In few word, you do and use a module and you only use a library.

When you want a specific function from a module or library you write:

from module/library import specific 

 


Learning don’t need to be boring

--Originally published at Welcome to the Heaven

Today I will teach you how to make a words counter and at the same time you will learn how to use the loopfor“.

First I need that you understand how it works this kind of loop. “For” is pretty different from while, because the second one will run the times that the answer be true, and the first one, the important for this post, “for” is going to repeat a certain number of times. 

Okay know we can start.

The program code that you’ll see is from a program that can count a specific letter from your text or count all the words that the input has. (If you want, I can help you to do that this program count a specific words, the only request is that you comment if you want it or I will teach you how to make that the program run with a document with text).

screen-shot-2016-10-27-at-1-07-25-amAs you can see the program have a question that serves to select if you want to count a specific letter or all the words.

We’ll focus in one answer to explain you how it “for” works.screen-shot-2016-10-27-at-1-14-42-amFirst to make the count possible, we define the variables that we going to use.

  -“count” makes that the program start to count in 0.

-“words” is the complete input.

-“word” is the same that words, the only thing that change is that we use <.split()> to     separate the words that have an space between and when we use this function the program can know that a group of letters with space is a word for us.

The loop for in this case makes that the count increment plus one, for a word that find in our variable “word”.

Continue reading "Learning don’t need to be boring"

One shot, a lot of points.

--Originally published at Welcome to the Heaven

Hi folks!! Today we will learn a lot of important topics in Python 3, like “Basic Output and Input”, “functions”, “use of if, elif and else” and how to make a “Loop” with while in a polite calculator.

The first step is create a function and the way to create a function is write def, next to the name of the function with parentheses and two points. Inside the parentheses we can write the variables that you’ll use in the function. #def is a block keyword to say to the computer that we’ll create a function an what will be its name

Example:screen-shot-2016-09-14-at-11-50-55-pm

After that we begin to write all the code of the function, in the case of the calculator we star with a output and input, to make the user feel comfortable.screen-shot-2016-09-15-at-12-06-21-am

In this case our Output is print(“Welcome”) that will say to the user the word <Welcome> and in the next line the Input will put <Do you want to use my Calculator? >   where you can write yes or noscreen-shot-2016-09-15-at-12-18-42-am

Okay, know we use a Loop with while, because we want that our calculator will never end if we don’t want so we write:screen-shot-2016-09-15-at-12-22-57-am

That’s means the program doesn’t have end if we write yes. In the final to close the loop we write. #<okay Bye> is only to be politescreen-shot-2016-09-15-at-12-26-29-am

When we have our loop, we can write the operations that our calculator will use. This prototype only work with addition, subtraction, multiplication and division, if you want you can make it work with more functions, like sin or cos…

The way to do all the operations is with the use of if, elif, input and output. Is pretty easy to do with this conditionals because the operations don’t need to import a

screen-shot-2016-09-15-at-12-40-00-am
screen-shot-2016-09-15-at-12-43-13-am
Continue reading "One shot, a lot of points."

I’m the type of…

--Originally published at Welcome to the Heaven

Okay, the basic data types in python 3 divides in 4:

  1. Boolean
  2. Numeric
  3. Sequences
  4. Mapping

 

The first one, Boolean is useful in conditional expressions and we used to the built-in values True and False.Boolean-data-type-in-java-programming

 

 

The second, Numeric divides in 3:

Screen Shot 2016-09-03 at 4.51.49 PM

The third, Sequences  divides in 3:

  • str = String; sequence of Unicode characters
  • byte: a sequence of integers in the range of 0-255
  • byte array: like bytes, but mutable
  • list = Can be mutable
  • tuple = Is immutable(need less space)

And the Fourth:

  • dict = Python dictionaries

 

This Basic Data Types is only for Python 3, not Python 2

 

If you want to read more about this you can visit:

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

https://en.wikibooks.org/wiki/Python_Programming/Data_Types

Picture:http://img.c4learn.com/2012/03/Boolean-data-type-in-java-programming.jpg


Is a python running on a Mac?

--Originally published at Welcome to the Heaven

Okay, not all the programmers begin programing with a Mac and don’t know about how run their programs in the terminal, for this, I’ll do this tutorial to make your life easier.

 

1.-Create your file in python and remember where did you put.

2.-Step 2: Open your terminal

3.-One more: if you put your file in a folder like Documents, you need to write:

>  cd documents

#”cd” give you access to the carpet that you write.

And you’ll be inside this folder.

4.-The last one: I suppose that you’re using python 3, so only write:

>> python3 banana.py

banana = name of your file.

Screen Shot 2016-08-29 at 10.32.30 AM

 

 

 


The best Poet of Python

--Originally published at Welcome to the Heaven

giphy-2

Do you know about Tim Peters?

The Zen of Python started like a joke of Tim, but with the time the people can see that these words had truth and this joke can become in a beautiful Poem for the Pythoneer that wants to become in a Pythonista.

For me the two best lines of the poem are:

If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
-Tim Peters
With this philosophy you can advance so fast that you will not have problems in the future, because you’ll do all the complex things become in easy.
Source: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
Picture: http://giphy.com/gifs/leighton-meester-gossip-girl-blair-waldorf-uEjQrtsl4Jokg