Funzioni In [ ]: print("ciao") In [ ]: def saluta(nome): print("Ciao %s"%(nome)) In [ ]: saluta("Stefano") Possono ritornare dei valori In [ ]: def somma(num1, num2): tot = num1 + num2 return tot In [ ]: somma(3, 2) i valori dichiarati all'interno di una funzione scompaiono al termine della stessa... ad esempio: In [ ]: print(tot) celsius to kelvin or fahrenheit In [3]: def convertemp(gradi): scelta = int(input("Convertire in Kelvin o Fahrenheit? (1 o 2): ")) if(scelta == 1): temp = gradi + 273.15 elif(scelta == 2): temp = gradi*(9/5) + 32 return temp In [6]: convertemp(3) Convertire in Kelvin o Fahrenheit? (1 o 2): 2 Out[6]: 37.4
Enter the password to open this PDF file:
-
-
-
-
-
-
-
-
-
-
-
-