ich bin wieder mit einer Übung von codecadmy. Bei dieser Übung
Define a function factorial that takes an integer x as input.
Calculate and return the factorial of that number.
Ich habe diese Lösung gefunden (leider konnte ich selbst nicht lösen)
[codebox=python file=Unbenannt.txt]def factorial(x):
result = x
count = x-1
while count > 0:
result = result * count
count = count - 1
return result
print factorial(5)[/code]
Ich verstehe nicht ganz, warum man hier eine Schleife braucht.
*Edit: Ich dachte, dass "factorial" schon integriert in Python war. Dann glaube ich, dass ich schon verstehe.
