fork download
  1. # Excluding not applicable arguments
  2.  
  3. def fact1(n):
  4. def f(n):
  5. if n == 0: return 1
  6. return n * f(n-1)
  7. if n < 0: return -1 # not applicable
  8. return f(n)
  9.  
  10. print("Factorial:")
  11. for i in range(-3, 17):
  12. print(f"{i}!={fact1(i)}")
  13.  
  14. def fib1(n):
  15. def f(n):
  16. if n <= 1: return n
  17. return f(n-1) + f(n-2);
  18. if n < 0: return -1 # not applicable
  19. return f(n)
  20.  
  21. print("Fibonacci sequence:")
  22. for i in range(-3, 21):
  23. print(f"f({i})={fib1(i)}")
Success #stdin #stdout 0.08s 14084KB
stdin
Standard input is empty
stdout
Factorial:
-3!=-1
-2!=-1
-1!=-1
0!=1
1!=1
2!=2
3!=6
4!=24
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800
11!=39916800
12!=479001600
13!=6227020800
14!=87178291200
15!=1307674368000
16!=20922789888000
Fibonacci sequence:
f(-3)=-1
f(-2)=-1
f(-1)=-1
f(0)=0
f(1)=1
f(2)=1
f(3)=2
f(4)=3
f(5)=5
f(6)=8
f(7)=13
f(8)=21
f(9)=34
f(10)=55
f(11)=89
f(12)=144
f(13)=233
f(14)=377
f(15)=610
f(16)=987
f(17)=1597
f(18)=2584
f(19)=4181
f(20)=6765