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 )

0 comments:

Post a Comment