这题怎么做?
>>> for x in range(1,1001):... if x%3==2and x%5==3and x%7==2:
... print("%6d"%x,end="")
...
23 128 233 338 443 548 653 758 863 968>>>
for i in range(0,1000):
temp = i
while temp:
if temp%3==2 and temp%5==3 and temp%7==2:
print(i)
DATEG 发表于 2022-10-13 09:27
for i in range(0,1000):
temp = i
while temp:
第5题怎么做 第五题:
def fun1(n):
if n==1:
return n
elif n%2 == 1:
return fun1(n-1)+1/fun2(n)
elif n%2 == 0:
return fun1(n-1)-1/fun2(n)
def fun2(n):
if n==1:
return n
elif n>=1:
return n*fun2(n-1)
print(fun1(10)) from fractions import Fraction # 导入这个模块可以让小数以分数的方式展示
n=int(input('前n项求和:'))
sum,temp=0,-1
for i in range(1,n+1):
temp=Fraction(temp*(-1)/i) # 每次循环temp都会比上一次多乘以-1/i
sum+=temp
print(sum)
页:
[1]