Creating your own Modules in Phyton

--Originally published at Ed_Alita

Creating a Module

This is the 2nd part of my last post. In a new document of phyton we are goig to create a module or librarie. Therefore the first thing to do is to define a funtion and what does the funtion have to do.

The next exmaple is on how to get the fibonnacci serie.

This is a very simple example:

fibo

In this second case is the same only it put the result in a list:

Then we save it as Fibo.py

Using it

Now we go to cywin or your compiler.

  1. We got to the location of our programs.
  2. Next we put python3 and presss enter.
  3. Then we import the Fibo archive.fiboex1
  4. Then we put Fibo.fib(10) With this we are calling a funtion that is inside of  Fibo.

fiboex2fiboex3

The information mentionted in this archive is in the next link

https://docs.python.org/2/tutorial/modules.html

 


Input = not so difficult

--Originally published at Py(t)hon

Hi again, today we are going to see how to make an input, it is actually not that hard so i think you won’t have any difficulties.

So this is how it goes:

Something = input ( whatever you want to ask)

Then you can go like:

Print = (“This” + Something + “ is very nice”)

Here is one example:

input1

Inputs are not difficult so don’t waste a lot of time with them, focus on more important things, but if you have difficulties you can always ask Ken.


Import and Used Libraries in Python

--Originally published at Ed_Alita

In Python there are all lot of functions that are not in it. In this cases they are called libraries which can be imported. There is a list on  which libraries are default in python3 here. Let’s how they work:

This how to import a libraries:

Screenshot from 2016-08-25 11-01-40

This code is how to run a simple random:

Screenshot from 2016-08-25 11-01-57

The Result of the code is the next one:

Screenshot from 2016-08-25 11-03-28

The resources of this information is the next one:

http://www.pythonforbeginners.com/random/how-to-use-the-random-module-in-python

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

 


Python’s Types of Data

--Originally published at Py(t)hon

Python has five standard types of data:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionary

The number type data is used to store numerical values, this are created when you assign a value to the object.

var1 = 5

var2= 15

Pythons support four different numerical types:

  • int ( signed integers )
  • long ( long integers, they can also be represented in octal and hexadecimal)
  • float ( floating point real values)
  • complex (complex numbers)

Some examples, for a clearer view:

int long float complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32.3+e18 .876j
-0490 535633629843L -90. -.6545+0J
-0x260 -052318172735L -32.54e100 3e+26J
0x69 -4721885298529L 70.2-E12 4.53e-7j

In the other hand we have the String which are a set of values represented inside a quotation mark.  Python allows either pairs of single or double. Subsets of the string can be made by a slice operator ([] and [:]). Every set starts at 0 to -1. You can include the sing (+) to add something else and the (*) to repeat that string a number of times. Here is an example for a better understanding:

string1

The next type is the list, where you will find items separated by commas and inside brackets, you can access to this list like the string but the difference is that it will appear the complete list of the place you chose, not only a letter or a value; also like the previous you can add something with the (+) and repeat the list with the (*) and example:

list1

The tuples are very similar to the lists, but the main difference is that the tuples are enclosed between parenthesis and not brackets as the list, and another main point is that

tuple 1
dictionarie1
Continue reading "Python’s Types of Data"

Functions in Python

--Originally published at Ed_Alita

what huh cece hannah simone new girl

The elemental thing to understand this topic is to define what a function is. It can be define as a block organized, reusable code that is used to perform a single, related action. The language of python by default is gave you a lot of functions but you can make your own functions.  Let’s see how we can do it:

1 Step

Define a function

In python you can define function to be use in you code. The  rules to make these are the followings:Geek & Sundry stranger things law rules rule

  • The functions begin with def followed by the function name and parentheses ().
  • Any input parameters or arguments should be placed within these parentheses.
  • The first statement of a function can be an optional statement.
  • The code block within every function starts with colon (:) and is indented.
  • The statement return exits a function, optionally  passing back an expression to the caller. A return statement with no argument is the same as return none

Syntax

def function-name( parameters ):
   "function_doc string"
   function_suite
   return [expression

Example

The following function take the parameter string and then print it

Screenshot from 2016-08-22 19-50-02

2 Step

Calling a Functionexcited great awesome oprah exciting

Defining a function only gave it’s name an the parameters of it. So how the hell I use this thing that I create.

To call a function is simple you only put the name and the parameters let’s see with printme().

Screenshot from 2016-08-22 19-50-21

The result of calling by this way is the next one.

Screenshot from 2016-08-22 19-51-57

Function with multiple arguments

This example is only to show you that you can have more than one argument inside a function.

Screenshot from 2016-08-22 19-50-43

This function requires two arguments therefore is more complex. The age can be initialized by any value in this case I use 35 only for the lols.

The result of calling it and running it is the

Screenshot from 2016-08-22 19-51-19
Screenshot from 2016-08-22 19-52-17
Continue reading "Functions in Python"

Print (Programing + Math)

--Originally published at Py(t)hon

This time we are going to see how to write and run basic math operations in Python, first we have to know the signs:

“+” is for summing

“-” is for subtracting

“*” is for multiplying

“/” is for dividing

“%” is for the remain of the division

Let’s start, for the past operations it doesn’t matter how many values do you want to sum, subtract, multiply or divide, it could be two to infinity, the important thing here is the sign.

Sum:

math1

Subtraction:

math2

Multiplication:

math3

Division & Remain:

math4

Here is the video that help me learned this stuff?

#Pug#Basic#TC101#Python#ISC It will continue…