martes, 15 de septiembre de 2015

Mastery 19 - Use of loops with While

I know how to use loops, its really simple. I will show you a WHILE loop that I used in the WSQ07:
This loop makes posible the constant repetition of one statement, it can also work with variables and numbers thats why I put the counter inside. The WHILE loop does not need parenthesis like the IF.

Masteries 15 and 16 - If and Else

Here I will show you that I know how to use IF and ELSE stamentes.
This is the basic form, I put it simple to understand the syntax quickly. Here are some works that I made using IF and ELSEs.

If you want to know more check my WSQs.

domingo, 13 de septiembre de 2015

Mastery 07 - Use of comments


Look now I know how to write comments in Python 3:


Materies 10 and 28 - Print and User input

Hello!! Here i´m going to show you how to write and print a text based user input.

Print text based user input


Lets say that you want to ask for the name of the user and then print it. It´s something very simple that requires an imput. Here I will show you my code:

In the code I created a variable called Name that is going to take the value of whatever the user           input is, inside the INPUT function I asked the user for his/her name. It´s important to keep the           user informed about what you want him to give you, always fill the parenthesis with the inormation     you want to ask him because f youi leave it in blank the user will not know what to write.

This is the code working:
As you noticed, the string that I wrote inside the INPUT function (between the parenthesis) is what Python asked me to write. Then I wrote my name and the variable Name took that string value. When the program printed Name it printed what I wrote.

In the PRINT function we are telling the program that we want to print the variable Name, this is not between the quotes because it´s a variable, remember that if you want to print a string you have to use the quotes. Also, you can combine variables and strings in the same PRINT function, let me show you:
 If i write "José Carlos" as my name and "17" as my age what this program should do is to print " Your name is José Caros Peñuelas and your are 17 years old". Lets see if this works:
 Well, something obviously went wrong. Lets see what it was.
 Oh I see now, the variables (shown in black by default) should be separated from the text with commas ",", this is the way that python recognize that you want a variable there  and not a string.
This is the correct way to do it, notice that i have the commas now:

The program will put the value of name and age between the strings. Notice that in the PRINT function I separated the variables from the strings with a comma. This is the code working:

Integer input

Now let´s try the same thing but with numbers:

This program is goint to tell the user to write a number, then is going to take that value and put it into num2 where is going to be added to 35. At the end is going to print 35 plus whatever the user wrote.

Lets see how it works:
AN ERROR?!?! Why? The print shuld be 40 because 5 + 35 = 40
This happened because the input value is always a string. Python ignores what the user wrote, it just take it as a string no matter if it´s a number or a word. But, what happens if i want to work with numbers? You have to tell python that you want that input to be an integer. To do that write the INT function and inside put eh input, like this:

Now python knows that the input is going to be an integer and now it can be used as a number. This is how the program should work: 

Now that you now how to use an input is important that you tell python what type of value you are expecting. If is a string the leave it that way, but if is an integer or a float be sure to write the type function and inside put the input. One very common mistake is that people forget to write a double parenthesis at the end of the input (like it´s shown on the picture above), be sure to close the INT function and the INPUT function always.





viernes, 11 de septiembre de 2015

Mastery 04 - Submit work


Here is the veidence:
-Submit work via Blog RSS
    I´m on the TC101 page and the first thing you see here is most recent entry about the mastery 1           and 2. This means that my Blog is registered and that the RSS is working.

-Submit work via Github
   This is my Github, there I have all the WSQ I have uploaded. I put the specific link to every one at      the end of each WSQ entry in my blog.

Mastery 03 - Twitter, Github and Blog


My Twitter is @JoseCarlPeAr
I don´t really use twitter that much, i just use it to see videogames or technology related news.

My Github is Jocapear
Here I upload all my code related to the class.

My Blogger link is http://jocapearpython.blogspot.mx/
Here i post every WSQ and mastery.

Masteries 01 and 02 - How to create, open and execute a Python file on Windows

To create a new file:

To create a file in python first you have to open the Python IDLE, to do this you have to go to the search bar and look for "python", there you willl see the IDLE exe.

The IDLE is like a comand line, you can´t write code on in, its just for testing. What you need to do to open a new blank space to write python code is to press "Ctrl+N  or to go to the corner and open a new file.

Now that you know how to create a new file, once you have your code written be sure to save it. It will be saved with a ".py" termination. 

To open/edit a file:

Once you have your file (you can even create it or download it) you will sometimes want to edit it, to write some extra code, finish your work or even correct somehing that was wrong. To do this first you have to localize your file: 
On the example I want to open the WSQ07.py file that I have in a folder in my desktop. 

I recommend you to memorize the files locations because if you want to execute it through the command line you will have to write the hole file adress. If you are bad at memorizing you should organize your files in jerarchised folders, this helps you to localize the file without not even knowing the exact location. Example: World/Continent/Country/State/City
This extructure will help you to go from something general to something specific without memorizing the exact adress. By the way, try not to use complicated names like "Masd123". Use something easy to remember that follows the logic of the jerarchy.

Continuing with the tutorial. The next step is to right-click on the file and select "Edit with IDLE". If you just open the file by double-clicking on it it will execute in the console or of it´s not finished it will not open anything. You should avoid opening .py files by double-clicking because the console that it launches will instantly run your code and when it ends it will close, you will not be able to see the prints or the results.
This will open the script so that you can continue writing on it.

To execute a file:

There are two ways of executing a file, through the command line and though the IDLE.
In my opinion opening it with the IDLE it´s a lot easier and you save a lot of time but it´s necessary that you know how to execute it with the command line because some text editors don´t have this option.

To execute the file with the command line(windows):

The first thing that you need to do is to open the CMD, look for it in the search bar and open it.
It will look like this:

Now you have to write the folder directory of your file, I highly recommend you to save the file on c:/ so that you don´t have to write the location every time you run the program. 

To find the root directory open documents go to C:/ users / (name of the user), there is where the CMD will start. Here is an example:


Now, once that you have localized your file location and you are ready to put it down on the CMD be sure to write "python" before the file separated with a space. This tells the CMD to excute the file with python (if you installed it correctly of course), the CMD will imitate the python console and execute the file you selected with it. 


Always remember to write the file termination, in this case is ".py".

To execute the file with the IDLE:

This is going to be really simple. First you need to open the file with the edit option that I teached you.

This is my WSQ07 and if want to run it while i´m using the IDLE I just have to pres F5... yes, just that. The console will open the file automatically.


As you can see it atomatically star asking me for the first number, that means that the program is running. 

Just as simple as that you can execute the file and test it without pressing more that 3 buttons, have in mind that in some computers you need to press Fn+F5.



martes, 8 de septiembre de 2015

WSQ07 - Sum of numbers

I have finally done WSQ07. This was an wasy one, once that you have learned the WHILE loops its really easy to work with them.

Here is my code:
and here is the code working:
I wrote the whole sum of numbers from 5 to 19 just to prove that my program is doing what I want it to do.

If you want to check my code on Github here is the link:
https://github.com/Jocapear/TC1014/blob/master/WSQ07.py

Quiz 04

I have completed all the tasks of the Quiz 4.
  Here is the prove that I have an account in Ken´s Blog.
My account is my student number : a01113339

viernes, 4 de septiembre de 2015

WSQ06 - Pick a number

Finally, this WSQ was a little bit for a challenge for me. Mainly because it was my first WHILE loop and the syntax is a little bit different, no "(",")" nor "{","}" and im very used to use them. Now its no problem because I learned to use WHILE loops on this link:
http://www.python-course.eu/python3_loops.php
Its very useful, if you are still having problems be sure to check this put.
Also, the random number generator was tricky, i couldn´t get the syntax well at first but after checking this link I could make it:
https://docs.python.org/3/library/random.html
This is my code

This is my code working
If you want to look at my code in Github here is the link:
https://github.com/Jocapear/TC1014/blob/master/WSQ06.py

martes, 1 de septiembre de 2015

WSQ05 - Temperature

This is my code in Python for calculating converting the temperature from Fahrenheits into Celcius. This is my first time using the conditionals IF and ELSE in Python.

Here are some things that I learned about Python on this exercise:
-The sintaxis is a little bit different from the other languages because it uses ":" instead of "{"
-Here the indentaion is important, you should write a conditional IF and then write with indentation what is inside it.

I´m going to show you an example, I used the program for this excercise.
The program working is this:



I learned all this by reading the book, it´s very useful.

If you want to check my code on Github this is the link:
https://github.com/Jocapear/TC1014/blob/master/WSQ05.py