求sin(x)的值。其中sin(x)=x-x3/3!+x5/5!-x7/7!+x9/9!-…,循环次数越多就越精确。
x=float(input())
r=0
for i in range(1,20,2):
m=1
n=x**i
for j in range(1,i+1):
m=m*j
if (i+1)%4==0:
r=r-n/m
else:
r=r+n/m
print(r)
求素数
for i in range(100,201):
for j in range(2,i):
if i%j==0:
a=0
break
else:
a=1
if a==1 and (i-1)%10!=0:
print(i)
斐波那契,迭代
def fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
return fib(n-1)+fib(n-2)
list1=[]
for n in range(20):
list1.append(fib(n))
print(list1)