Wednesday, October 29, 2008

Funny Sayings Restraunts

013) The global variables

As we have studied, when you create functions state variables (known as local variables) they are all 'inside the function block with instead declare global variables that can be used in all the functions. Some examples:

EXAMPLE OF ERROR NOT GLOBAL VARIABLE:
 
final calcoloeta () :
year = 2008
tuoanno = input ( "In what year were you born : )
age = years - tuoanno
print " Hai ", eta ," anni "
calcoloeta ()
print " Siamo nell' anno ", anno #si richiama la variabile
#anno


Output:
  
In che anno sei nato: 1985
Hai 23 anni
Siamo nell' anno
Traceback (most recent call last):
File "prova.py", line 25, in
print "We're in 'year', year
NameError: name 'year' is not defined

What's happening? The interpreter returns error because the line print "We're in 'year," year we try to recall the year that variable within the function as a local variable is then valid only inside the function the problem can be solved by declaring years as a global variable:
 
final calcoloeta () :
global years year # becomes a global variable
years = 2008
tuoanno = input ("What year were you born : )
age = years - tuoanno
print" You " age, " years "
calcoloeta ()
print "We are in ' years, years # # relies on the variable
years

In this case there should be no mistakes because years although a variable within a function and "uttilizzabile all" thanks to global.

Grinding Dancing With A Belt

012) 's return statement

need to return back to caller with return values, as we look at the example returns a value:

 
final age () :
et = input ( how old are you?: )
return et # et and then returns the value of your age
# '

print age () # print a video la funzione eta
#se eta non ha valore stampa None

Che succede?? print eta() stampa a video la funzione con la variabile di ritorno richiamata da return facciamo un altro esempio:
  
def eta ( x , y ) :
risu = x + y
return risu
print eta ( 2 , 4 )

This example is better understood by changing the parameters of the print age (2.4) function is called and prints to video the value of the variable would return ECJ risu the result of an operation mathematics. the interesting thing is that we can assign to a variable in the entire opearzione a function like this:
 
final age ( x, y ) :
risu = x + y
return risu
to = age (2 , 4) # to become the return value
print " twice the function and operation ' " to + to

All this is possible thanks to the return value. In print "function and the dual operation, '" a + a print to video the first string and then the sum of the return value for himself.

Thursday, October 23, 2008

A Spy Is Being Chased Down The River

E001) Introduction to computer algorithms Michele Broggi

The following post was created by Michele Broggi per sua gentile concessione lo posto sul mio blog. L'indirizzo del post è il seguente http://www.michelebroggi.it/programmazione/introduzione-agli-algoritmi-informatici.html


Introduzione agli algoritmi informatici :

15 Agosto 2008

In informatica , con il termine algoritmo si intende un metodo per la soluzione di un problema adatto a essere implementato sotto forma di programma .

Intuitivamente, un algoritmo si può definire come un procedimento che consente di ottenere un risultato expected running, in a certain order, a set of simple steps corresponding actions usually chosen from a finite set.

For more information, please refer to the wikipedia page , which mentions several things of algorithms: their origin (history) to their use and application.

The image above is for a published flowchart , they allow us to "draw" in concept (especially graphics), an algorithm.

As we can see our diagram consists of: start , input, processing , output , end.

Exactly what happens in any program.

Certainly in the future to publish more articles about algorithms, the basic foundation of computer science.

Monday, October 20, 2008

Free Vietnameses Movies

11) The functions PART 2 (parameters)

In the second lesson of the functions we introduce the parameters. The parameters (which are inside the parentheses when we create a function) are nothing more than to be uttilizzate variables in the function block, now a very simple example:
 
final addition ( x, y ) : # defines the function addition ()
print x + y # instructions function
addition (1 , 1) # call the function with other parameters

Output:
 
2

What's happening? When you call the function x and y values \u200b\u200bbecome the values \u200b\u200bthat we have made at the time that we call the same function addition (1.1) so that education becomes print print x + y 1 +1.
We can also use strings for parameters as shown in example
  
def domande(primo,secondo) : #definisce una funzione
print " il tuo nome e' ") + primo #istruzioni
print " il tuo cognome e' " + secondo #istruzioni
nome = raw_input (" scrivi il tuo nome: ") # istruzioni FUORI dalla funzione
cognome = raw_input (" scrivi il tuo cognome: ") # da notare l'identazione appunto
domande ( nome , cognome ) #chiamata alla funzione con parametri

Stesso discorso di prima basta cambiare i parametri al momento del richiamo per usare il blocco del codice della funzione a nostro piacimento.
Da questo si può capire l'importanza e l'utilità delle funzioni

Esercizio: Scrivere un programma che calcoli l'area di un quadrato mettendo la formula matematica nella funzione e cambiando i parametri in modo che we use the values \u200b\u200bentered from the keyboard (<--ma questo è italiano? XD )

Sunday, October 19, 2008

Why Do Ice Skates Hurt The Arch Of My Foot

10) The functions PART 1

Functions are blocks of code repeated. Let's see how you define a function:

 
# / usr / bin / python

final test ( ) : # def initialize and are used with:
print "hello world " # code from the function

test () # function call


What's up? with final test (): you create a function is defined by final you give a name test () and using the : in the name of the function using the brackets () because they contain (if you need) the parameters, the code that comes after print "hello world" is unique code of the function means that if the function is invoked test () that code will not run.

Let's see how to use two or more functions together
 
# / usr / bin / python

final test () : # define a function:
print "hello world " # codice contenuto nella funzione

def linea () : #definisce una funzione
print #linea vuota

def due () : #definisce una funzione
linea () #chiamata alla funzione linea()
prova () #chiamata alla funzione prova()
linea () #chiamata alla funzione linea()

due () #chiamata alla funzione


Output:
  
bash-3.1 $ python prova.py

hello world

bash-3.1 $


What's happening? re-reading the code we can find that we call the function * only * two () But she draws the first line () where your code will print a blank line, then test () , which prints hello to video world, then again line () and we will have a blank line.

* * TO REMEMBER:
function calls must have the ().
USE identity

Thursday, October 9, 2008

Homeopathy Alopecia Barbae

9) Start: The loop

cycle for incrementa una variabile con delle sequenze in looping. Nel senso che cambia il valore di una variabile in un ciclo vediamo un esempio:
  
   #!/usr/bin/python 

for
num in range ( 0,10 ) :
print num
Output:

0
1
2
3
4
5
6
7
8
9

Che succede?? for a in range serve a cambiare il valore della variabile num in sequenza che va da 0 a 10. range serve proprio a questo for ... in range(inizio, fine) , se volessimo aggiungere uno step (una specie di salto nel conteggio) basta aggiungere un terzo elemento a range(0,10,2) Proviamo:
  
   #!/usr/bin/python 

for
num in range ( 0 , 10 , 2 ) : #2 e' lo step
print num
As you can see the sky missed the second sequence of numbers printed on the screen 0,2,4,6,8.
Other uttilizzi of for with strings look in the example:
 
 
   # / usr / bin / python 
for num in ( " H " , " and " , " the " , " the " , " or ", " , " W " , " or " , " r " , " the " , " d) :
print num, # not the comma is used to wrap
 

What's up? will simply output the string "H ello W orld" the cycle takes its value from the first point until the 'last.
for can also use variables such as: for a in b where b is a string maybe.

* * REMEMBER TO
If you are using for in (0.10) without printing on the screen range 0 10 range just need to get a count from the first value in the second .
The comma used in the function print () (eg: print a,) is not to go head adds more space.

 

 

Sunday, October 5, 2008

Scab On Nipple In Early Pregnancy

8 ) begin while (looping)

Education while allows us to repeat a block of statements until the condition is true, an example is better:

  # / usr / bin / python    

a = 0 #inizializza la variabile
while a < 10 : #continua finche' a e' minore di 10
print a #stampa a video a
a = a + 1 #addiziona il valore di a+1


Che succede?? while a <10: ci dice che il codice di blocco che seguirà sarà ripetuto finche a è minore di 10 partendo da 0 fino a 9 (10 numeri in tutto!!), a=a+1 assegna ad a il proprio valore +1 significa che ad ogni ciclo la variabile a aumenta di 1

While può avere un ciclo infinito semplicemente avendo la condizione True .
  
#!/usr/bin/python

stringa = " Plaoo " #inizializza una stringa
while True : #continua finche' a e' minore di 10
print stringa #stampa stringa

In questo caso stampa a video "Plaoo" per infinito non ha una condizione control for this we come to the aid else (as seen if):

  # / usr / bin / python  

password = " code " # initialize the string to
= True
while to : #, and then true
ins = raw_input ( Enter Password: " )
if ins == password : #se ins e' uguale a password
a = False #per bloccare il ciclo while la condizione diventa false
else:
print " Il ciclo e' finito " #Stampa a video
#quando la condizione
#di while e' falsa



Che succede?? Un semplice programma per il controllo della password, a = True ci serve per cambiare il valore della condizione sul while lo dobbiamo mettere su una variabile altrimenti non possiamo modificarne value. Else you'll see how it is not necessary but you can use to write code more readable.

Exercises: Make a plan
countdown

Tuesday, September 30, 2008

Show Me Boobs Of Indian Heroines

7) Begin: if statement, elif and else

Education allows us to check if a condition is met if the condition continues else and otherwise processing a different block. Here is an example which is better:

  
# / usr / bin / python

name = raw_input ( What's your name? )
if name == " plaoo " : # check if name and 'equal to "plaoo"
print " Bravooo " # if the condition and' respected print to video "Bravooo"
else : # If the condition is not met
print "Your name is " + name # print to video "Your name is" + the string variable name

As you can see there are spaces after else if and this is called indentation. In python E ' you can use 4 spaces required or (as I do io) un TAB . Se usate TAB ricordatevi che l'istruzione non sarà eseguita . Con i 4 spazi, invece, restituisce l'errore se l'identazione è sbagliata.

Spieghiamo meglio, if nome == "plaoo" : se nome è uguale (==) a "plaoo" se è così allora stampa "bravooo"
else altrimenti stampa "ti chiami" + il valore di nome.
L'istruzione if ha bisogno di operatori di confronto come == nell' esempio precedente e questi sono quelli uttilizzati:
  
< minore di
> maggiore di
==
equal to or less <=
> = \u200b\u200bgreater than or equal to
! =
other


another example with variables Numeric:
  
# / usr / bin / python
numero_magico = 8
number = input ( Pick a number from 0 to 10: )
if numero_magico == number :
print "Congratulations you have guessed the number "
elif number > numero_magico :
print "Too high "
elif number < numero_magico :
print "Too low "


What's happening? After creating the variable numero_magico user is prompted to choose a number if numero_magico ( if numero_magico ) is equal (== ) to number Press a video "Complimenti hai indovinato il numero" ( print "Complimenti hai indovinato il numero" )
altrimenti se numero ( elif numero )è maggiore ( > ) di numero_magico stampa a video "Troppo alto" ( print "Troppo alto" )
altrimenti se numero( elif numero ) è troppo basso ( < ) di numero_magico stampa a video "Troppo basso" ( print "Troppo basso" ). Possiamo usare tutti gli elif che vogliamo per avere il controllo delle variabili.
elif viene usato come if , cioè può fare un confronto con le condizioni else instead is used when none of the comparisons with the conditions.

* * TO REMEMBER: Use
indentation which would be spaces after if, elif and else.
All statements must end with ":"

Sunday, September 28, 2008

Pathophysiology Polyps

6) start: Keyboard Input

For keyboard input is meant, of course, the keys are pressed on the keyboard. The python has two instructions that allow us this raw_input () and input (). raw_input used in this way:

string = raw_input (" write here: ) # everything verra scritto sarà la variabile stringa

Un altra cosa interessante è che raw_input() ti permette di stampare a video una stringa ("scrivi qua:) da ricordare che bisogna mettere tutto tra parentesi. input() funziona allo stesso modo:

numero = input (" scrivi qua: ")

Funziona esattamente come come raw_input() . E allora perchè usare due istruzioni se compiono lo stesso compito?? In realtà raw_input() crea variabili di tipo stringa mentre input() variabili intere (o numeriche). Come abbiamo visto nella precedente lezione le variabili stringa e le variabili numeriche sono incompatibili tra loro dovete stare molto attenti quando usate queste due istruzioni o vi capiterà molto spesso di avere errori.

Esempi pratici:

#!/usr/bin/python
nome = raw_input (" Come ti chiami?? ") #procedura per creare la variabile nome
anni = input ("quanti anni hai?? ") #crea la variabile anni che è un intero
print nome #stampa a video la variabile nome
print anni #stampa a video la variabile anni

ecco l' output:
   Come ti chiami?? 
Plaoo
23
Che succede?? Semplicissimo ad ogni istruzione che sia raw_input() o input() il programma si blocca e attende l'input da tastiera che poi va a stampare a video con le instruzioni print nome e print anni.

Per scoprire che tipo di variabile abbiamo possiamo usare type() . type() ci fa vedere il di tipo variabile che stiamo analizzando in questo modo:

name = raw_input (" What's your name? ) # procedure to create the variable name
type ( name ) # check what kind of variable We
print name

the output is this:

What's your name?
\u0026lt;type'str'>
Plaoo

What's happening? the first and the last one, but we know what that \u0026lt;type'str'>? In Here type () returns us the type of variable in this case 'str' because it is otherwise, it returns a string if it were an integer.

Exercise: Create a program after a series of questions create a profile of a person looking to also use the string concatenation


Wednesday, September 24, 2008

Old Man Breastfeeding

5) Start: Numeric variables (starts a little math)

as string variables, numeric variables can also change the their value during the execution of the program, even MUCH more, given that we use for mathematical purposes (of course being numbers). Numeric variables declared in the same way as string

num = 1

Da notare che non usiamo gli apici "" altrimenti il python la riconoscerebbe come una stringa, è possibile applicare solamente l' operatore matematico * , tutti gli altri operatori creano errori tra i due tipi di variabili se provassimo a fare un programma del genere:

num = 1
fra = "ciao"
print num + fra

questo sarà il risultato:

Traceback (most recent call last):
File " ", line 1, in
TypeError: unsupported operand type (s) for +: 'int' and 'str'

Just because there are two different variables. Numerical variables we can apply the mathematical operators in python are these:
  +  
ADDITION - SUBTRACTION
/ DIVISION
* REPRODUCTIVE
** Exponentiation

Try a few simple steps:

num = 3 # declare numeric variable with a value of 2
num2 = # 2 ditto of course with a name different
print num - num2 # print out your results

What's happening? In this case there is a simple subtraction num (with a value of 3) - num2 (with value 2) prints the result 1.

diachiarare We can use variables for the operation this way:

num = 3 # declare numeric variable with a value of 2
num2 = # 2 ditto of course with a different name
risu = num - num2 # Variables that includes the operation and the result becomes the same
print risu # print the variable video risu

What's happening? in this case we used another variable to make it the result of 'operation itself so that we can use the result for other purposes, simply call the variable risu and work on it another operation, eg

num = 3 # declare numeric variable with a value of 2

num2 = 2 # ditto obviously with a different name
risu = num - num2 #questa varibile racchiude l'operazione e diventa il risultato stesso
print risu #stampa a video la variabile risu

risu = risu * 5
#usiamo la variabile risu per applicarle un altra operazione risu * 5 moltiplichiamo risu per 5 volte
print risu #stampa a video il risultato

Che succede?? Dopo che stampiamo a video il risultato della sottrazione num - num2 lo stesso risulato che adesso è risu lo moltiplichiamo per 5 e stampiamo a video il risultato a questo punto risu a valore 5 e non più il risultato della sottrazione precedente.

Come in matematica l'uso delle parentesi ( ) ha precedenza rispetto a tutto il resto vediamo un esempio:

num = 4
num2 = 2
risu = ( num + num2 ) * 2
print risu

Che succede?? In questo caso l'operazione racchiusa tra parentesi ha la precedenza sulla moltiplicazione (come in matematica)

Tips & Tricks: try to create a string variable and multiply it by 2!

Exercise:
1) Create a program using all the addresses on less variables as possible.
2) Create a program to calculate the mathematical average.

Quickbooks Premier Product Number

4) Here we go: The string variables

To varying means, a portion of memory that can be changed during program execution. It's that simple! If we wanted to create a string variable just write

string = "hello world" # The variable becomes a string
print string # print-screen the string

What's happening? print, as we saw in the previous lesson, press the screen in this case the variable contains a string and we just read the string. We said that the variables can be changed during program execution so if you write well?

string = "hello world" # variable has the value "hello world" string
= "Hello World" here instead becomes # hello world "
print string

What's happening? In this case, the string variable value change at the beginning is "hello world" in the line next sequence becomes "Hello World". If you do a test print you will find that video print "Hello World" becomes the ultimate value that the variable string. You can assign any name to the variable except those reserved to python:

else for continuous and not raise import

assert def except from in or return
global break exec is try
class pass elif if finally lambda print while

How to concatenate variables: If we wanted to join
2 o più variabili potremi usare il simbolo " + " in questo modo:

stringa = "Hello " #da notare lo spazio lasciato alla fine prima dell apice
stringa2 = "world"
print stringa + stringa2

in questo caso output (il risolutato che ne consegue) sarà questo:

Hello world

Per fare delle prove (e vi consiglio di farne tante per restarvi in mente) usate il metodo usato nella lezione precedente create un file chiamato prova.py e fatelo eseguire dal terminale con python prova.py

Che sono quelle frasi dietro # ?? Si tratta di un commento, potete scrivere i vostri commenti a fianco al codice in modo tale da prendere appunti su quello che fà il programma sono utilissimi e vi consiglio di utilizzarli il più possibile.

Esercizio: Create 3 variabili che concatenate formino una frase di senso compiuto

Tuesday, September 23, 2008

Thank You Messages Wedding Program

3) Start: First script (already?!?)

Si possiamo benissimo iniziare a scrivere il nostro primo script ( o programma come volete voi). Iniziamo già dalla terza lezione perchè in questo blog non intendo perdere tempo sull informatica teorica qua si pratica e basta ;-). Bene iniziamo... Ok create un file di testo, potete usare quasiasi editor, scrivete:

print "hello world"

Save as prova.py . Go to the terminal position yourself on the folder where you saved the file and type python prova.py if the result is this:

bash-3.1 $ python hello world prova.py


Well you have written your first program in python (to know the history of hello world read in this page ) now is an explanation of print script screen is used to print any string, or variable, it seems obvious that in this case the string is "hello wolrd" but it could very well be "Hello mom." Remember the string must be enclosed in quotes "" otherwise we will have an error.

Exercise: Write a program that prints three strings 2 with random phrases and the center should remain empty as you do? You can write the script on the comments

Monday, September 22, 2008

Zinc And Castor Oil Cream

2) Start: Where to find the 'python interpreter

If you use a Linux distribution to 90% is already installed walk- open the terminal and enter the command python if the result is this:

bash-3.1 $ python

Python 2.5.2 (r252: 60911, Mar 1 2008, 13:52:45)
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

type:
>> exit () to exit


If you can do whatever peace of mind that your python is already installed otherwise you can find it in the repository of your distribution

If you use a system Microsoft Windows http://www.python.org/download/ go on to download the 'installer. On the site
python.org you can also find sources of 'interpreter.

Stouffers Outlet Solon Ohio Phone Number

1) Start: What is python?

The python is a language interpreted programming. Interpreted means that after you create the program need not be completed because the 'interpreter "reads" the code as written. example source code
----- ----- interpreter python> program execution
The cool thing about it is that the Python interpreter has a huge portability you can use it on your mobile phone (Symbian OS) on Windows, Linux, Mac etc etc. In short, you can use python really everywhere, the simplicity of this language is the state 's work, and this blog will teach you a simple to use all the capabilities of python.