Code: Alles auswählen
def test():
print txt
test( "geht nicht" )
Code: Alles auswählen
def test( txt ):
print txt
test( "das geht" )
Code: Alles auswählen
def test():
print txt
test( "geht nicht" )
Code: Alles auswählen
def test( txt ):
print txt
test( "das geht" )
wo scheibst du das rein? In eine Datei?also meinst du jetzt ich soll das alles so eingeben
Und ich frage nochmal, was für einen Fehler teilt dir Python mit?dann kommt mal wieder eine fehermeldung
Code: Alles auswählen
x = -4.5 + 0.5
Code: Alles auswählen
def wertetabelle(a, b, sw):
x = a
while x <= b:
y = die funktion
print x, y
x = x + sw
Code: Alles auswählen
x=-4.5 / y=50.11875
x=-4.0 / y=32.0
x=-3.5 / y=19.29375
x=-3.0 / y=10.8
x=-2.5 / y=5.46875
x=-2.0 / y=2.4
x=-1.5 / y=0.84375
x=-1.0 / y=0.2
x=-0.5 / y=0.01875
x=0.0 / y=0.0
x=0.5 / y=-0.00625
x=1.0 / y=0.0
x=1.5 / y=0.16875
x=2.0 / y=0.8
x=2.5 / y=2.34375
x=3.0 / y=5.4
x=3.5 / y=10.71875
x=4.0 / y=19.2
x=4.5 / y=31.89375
x=5.0 / y=50.0
x=5.5 / y=74.86875
Code: Alles auswählen
def wertetabelle(a, b, sw):
x = a
y = die funktion
while x <= b:
print x, y
x = x + sw
Code: Alles auswählen
def wertetabelle(a, b, sw):
x = a
while x <= b:
y = 0.1*x**4 - 0.1*x**3 - 2.4*x**2 + 0.4*x + 8
print x, y
x = x + sw
wertetabelle(-4.5, 5.5, 0.5)
Code: Alles auswählen
#!/usr/bin/env python
# -*- encoding: latin-1 -*-
def xlrange(start,stop=None,step=1):
"""xlrange([start=0,]stop[,step=1]) --> iterator object like xrange for longs"""
if stop==None:
stop=start
start=0
if step>0:
while start<stop:
yield start
start+=step
elif step<0:
while start>stop:
yield start
start+=step
else:
raise ValueError, "xlrange() arg 3 (step) must not be zero"
def process(x):
return 0.1 *x ** 4 - 0.1 * x ** 3 - 2.4 * x ** 2 + 0.4 * x + 8
def wertetabelle(start, stop, step):
for x in xlrange(start, stop + step, step):
print "x=%0.1f\t y=%0.5f" % (x, process(x))
if __name__ == '__main__':
wertetabelle(-4.5, 5.5, 0.5)
Code: Alles auswählen
x=-4.5 y=7.71875
x=-4.0 y=0.00000
x=-3.5 y=-3.50625
x=-3.0 y=-4.00000
x=-2.5 y=-2.53125
x=-2.0 y=0.00000
x=-1.5 y=2.84375
x=-1.0 y=5.40000
x=-0.5 y=7.21875
x=0.0 y=8.00000
x=0.5 y=7.59375
x=1.0 y=6.00000
x=1.5 y=3.36875
x=2.0 y=0.00000
x=2.5 y=-3.65625
x=3.0 y=-7.00000
x=3.5 y=-9.28125
x=4.0 y=-9.60000
x=4.5 y=-6.90625
x=5.0 y=0.00000
x=5.5 y=12.46875
xt@ngel als gast hat geschrieben:Jo hab grad festgestellt das ich die Formel falsch hab....
hab die von mawe 1 zu 1 kopiert ohne dein post zu lesen
Code: Alles auswählen
def funktion(x): #1
return (0.1*(x**4)) - (0.1*(x**3)) - (2.4*(x**2)) + (0.4*x) + 8.0 #2
def wertetabelle(f,start,stop,schritt): #3
h = start #4
while h <= stop: #5
print h,' ',f(h) #6
h += schritt #7
wertetabelle(funktion,-4.5,5.5,0.5) #8
Wollte nur mal anmerken das die Doku zu der Funktion etwas zu einschränkend ist. Wie man in diesem Fall sieht ist sie nicht auf `long` beschränkt sondern funktioniert auch prima mit `float`.Leonidas hat geschrieben:Ich hätte es ja so gelöst, das macht mehr Eindruck (finde ich) und ist auch irgendwie simpler (bis auf das xlrange, aber das versteht man auch):Code: Alles auswählen
#!/usr/bin/env python # -*- encoding: latin-1 -*- def xlrange(start,stop=None,step=1): """xlrange([start=0,]stop[,step=1]) --> iterator object like xrange for longs"""
Ja, durchaus, aber ich habe sie einfach 1:1 von Milan kopiert ohne mir über die Doku Gedanken zu machen.BlackJack hat geschrieben:Wollte nur mal anmerken das die Doku zu der Funktion etwas zu einschränkend ist. Wie man in diesem Fall sieht ist sie nicht auf `long` beschränkt sondern funktioniert auch prima mit `float`.