martes, 10 de febrero de 2015

Use of "elif"

#mastery17.
The elif statement is a conditional statement that is short for 'else if'. It goes right after an if statement and is good so you can prevent exesive identation.
This qwick program uses both the if and elif statements, as well as an final else stament.

I hope this was usefull in your if statesment programing.  

To learn more about if staments Click Here.

lunes, 9 de febrero de 2015

#WSQ07 Sum of numbers

This was quite a fun program to make. I used a While loop, you can see the code and the terminal runing in the picture, as well as a online calculator prooving that that the answer is right.

Using a While loop

A while loop is used in a similar fashin that the conditional loop, exept this will run every single time that the condition in it is found to be truth.

So you have your basic stuff. You grite your conditional inside parenthesis followed by a colon, and then you write all the code you want the program to repeat till the condition is truth in the following line with an identation.

example:

x = int(input("give me a number"))
while(x!=0):
           if(x>0):
                  print(x," is a positive number")
           if(x<0):
                  print(x," is a negative number")
           x=int(input("Change the number: ")
if(x==0):
          print(x," is cero")

In this case the program wont stop (it wont get out of the loop) untill you tipe the number "0". 

Again the Random númber program is a great exaple using the while loop.


Use of the conditional IF

The random numbers program in here shows a great example of the If conditional being used. You basically set your conditinial, write a colon, and in the next lines you write the code with an identation of all the steps that will follow beeing the conditional truth. 
example: 
x = int(input("give me a number"))
if(x>0):
           print(x," is a positive number")
if(x<0):
          print(x," is a negative number")
if(x==0):
          print(x," is cero")


Coments in Python

It's real simple. You write whatever you want to coment right beside your code, sandwitched in between two '#' simbols.

jueves, 5 de febrero de 2015