Latest web development tutorials

Python beinhaltet 26 Übungen

Python 100 Li Python 100 Li

Titel: rekursive Methode Anfrage 5!.

Programmanalyse: rekursiven Formel: fn = fn_1 * 4!

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

def fact(j):
    sum = 0
    if j == 0:
        sum = 1
    else:
        sum = j * fact(j - 1)
    return sum

for i in range(5):
    print '%d! = %d' % (i,fact(i))

Das obige Beispiel Ausgabe lautet:

0! = 1
1! = 1
2! = 2
3! = 6
4! = 24

Python 100 Li Python 100 Li