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