Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. Eine Funktion kann erst einmal als Unterprogramm betrachtet werden, z.B. <code python> def hello(): print "Hallo Welt!" hello() # Führt die Funktion aus </code> Es können Argumente (Parameter) übergeben werden, z.B. <code python> def bla(n): print "bla "*n bla(3) # Gibt "bla bla bla " aus </code> Es können aber auch Dinge als Resultat zurückgegeben werden, z.B. <code python> def doppelt(n): return 2*n print doppelt(7) # Gibt 14 aus </code> Oder etwas komplizierter: <code python> def mitternachtsformel(a,b,c): d=b*b-4*a*c if d<0: return [] # Leeres Array if d==0: return [-b/(2*a)] # Array mit einem Element d=d**0.5 # Wurzel d return [(-b-d)/(2*a), (-b+d)/(2*a)] # Beide Lösungen in einem Array print "Loesung von 5x^2-7x-2:" print mitternachtsformel(5,-7,-2) print "Loesung von 5x^2+x+10:" print mitternachtsformel(5,1,10) </code> lehrkraefte/blc/informatik/ffprg1-2019/funktionen.txt Last modified: 2019/02/10 11:35by Ivo Blöchliger