INT104-lab2

 1 import math
 2 import sys
 3 
 4 def f(dep,fib):
 5     if dep==10:
 6         print(fib*dep)
 7     else:
 8         fib=fib*dep
 9         f(dep+1,fib)
10         print(fib)
11 
12 
13 def e(max):
14     fib=ans=1
15     for i in range(max):
16         fib*=i+1
17         ans+=1/fib
18     print(ans)
19 
20 
21 def sol(a,b,c):
22     delta=b*b-4*a*c
23     if a==0:
24         sys.stderr.write("a=0\n")
25     else:
26         if delta>=0:
27             return (-b+math.sqrt(delta))/(2*a),(-b-math.sqrt(delta))/(2*a)
28         else:
29             sys.stderr.write("delta<0\n")
30 
31 if __name__ == '__main__':
32     f(1,1)
33     e(10)
34     sol(1,5.86,8.5408)
35     sol(0,1,1)
36     sol(1,0,1)

 

posted @ 2021-03-08 17:54  墨鳌  阅读(118)  评论(0编辑  收藏  举报