def faktorial(n):
if n <= 1:
return 1
else:
return n*faktorial(n-1)
for i in range(11):
print "%2d ! = %d" % (i, faktorial(i))
Output:
0 ! = 1
1 ! = 1
2 ! = 2
3 ! = 6
4 ! = 24
5 ! = 120
6 ! = 720
7 ! = 5040
8 ! = 40320
9 ! = 362880
10 ! = 3628800
Tidak ada komentar:
Posting Komentar