Skip to main content
 

Mastery19 - While loop

1 min read

the while loop will go on until the condition to break it is met and can run undefinedly.

to use it write while and the condition>

while x < 50:

         do something

reference:

https://wiki.python.org/moin/WhileLoop

 

Mastery18 - Nesting of conditional statements

1 min read

nesting is when you put conditionals inside other ones to check another condition. 

if something:

            thing1

            if something2:

                         this

             else:

                       that

there is an if and else conditionals inside the initial if.

reference:

http://www.tutorialspoint.com/python/nested_if_statements_in_python.htm

 

Mastery17 - Conditional elif

1 min read

the elif conditional es a combination of the else and if conditionals, it needs a to fulfill a conition like the if conditional but it will be ignored if the condition above is fulfilled like an else conditional.

if we had this conditionals:

if x != 0:

   print("it's not a 0")

if x > 0:

   print("more than 0")

if x < 100:

   print("less than 100")

and we used 50 as x, the program will print everything since 50 meets each condition but if we change any of the if conditionals after the first to elif the program would ignore them since the first will be true. elif is to stick two statements as one.

 

Mastery16 - Conditional else

1 min read

the else conditional goes after an if conditional, when none of the conditionals above is fulfilled then the else conditon is used. for example:

x = 5

if x < 5:

if x > 5:

else:

    print ("it's a 5")

the rpogram wil use else since none of the conditions above was fulfilled.

 

Mastery15 - Conditional If

1 min read

the conditional if es used whe you want something to happen only when a a certain condition is met. like comparing two variables and if they are equal the the program will follow the contition.

x = input()

y = input()

if x == y:

    print ("it is the same")

 

 

Mastery14 - Creating a python module

1 min read

creating a module is no different from a normal program, create a python file and create a few functions in it.

file name: mymodule.py

def function1():

      print ("function 1")

# end of the module.

and in another program import it an call the function:

import mymodule.py

mymodule.function1()

reference:

http://www.ibiblio.org/g2swap/byteofpython/read/making-modules.html

 

Mastery13 - Importing and using python modules

1 min read

to import modules write import and the name of the module you want.

import random

and now you can use the functions of that module.

here is a list of modules in python:

https://docs.python.org/3/py-modindex.html

 

Mastery12 - Creating python functions

1 min read

Creating a function in python is not hard, give it a name and give it a job.

to create it first we need to define it, giving it a name and a number of variables it needs.

def  adding_function(a,b):

and inside the function the operation it will perform, this function will add a + b and return the result.

def  adding_function(a,b)

       return a+b

now call the function to add two numbers.

reference:

http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6/Defining_Functions

 

Mastery11

1 min read

In python to call a function write the name of the function and the variables it needs, for example:

function_name (x,y)

and you can call a function to give value to a variable.

z = function_name(x,y)

 

Mastery10 - Basic output: print in python

1 min read

Telling a program to print is to display information on screen. to use it in python write print() in the parentheses write the data you want to see on the screen.

example:

print ("hello world")

the program should display "hello world" on the screen when you run the program, also it can print the value of a variable:

x = "hello world"

print (x)

and "hello world" will apear on the screen, not "x".