Variable macht while unbrauchbar
Verfasst: Samstag 11. Juni 2011, 02:33
Hallo,
folgender Code funktioniert ohne Probleme wenn keine Variable benutzt:
Sobald ich aber eine Variable einbringe (zahl):
wiederholt sich die Schleife endlos.
Woran liegts?
folgender Code funktioniert ohne Probleme wenn keine Variable benutzt:
Code: Alles auswählen
def loop():
i = 0
numbers = []
while i < 10:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is: %d" % i
print "The numbers: "
for num in numbers:
print num
loop()
Code: Alles auswählen
def loop(zahl):
i = 0
numbers = []
while i < zahl:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is: %d" % i
print "The numbers: "
for num in numbers:
print num
zahl = raw_input("> ")
loop(zahl)
Woran liegts?