from math import *
import os
def f(x,a,w):
y = sqrt(1+pow(cos(w*x),2))
return y
def myf(begin,end,a,w,g):
result =0
count= 1000000
delta = (end-begin)/count
for i in range(count):
result += delta*g(begin,a,w)
begin += delta
return result
while(True):
a,w,begin,end = map(float,input().split())
r= myf(begin,end,a,w,f)
print(r),
縮進修改一下,運行后,用空格分隔輸入4個數(shù),可計算出來結果。
from math import *
import os
def f(x,a,w):
y = sqrt(1+pow(cos(w*x),2))
return y
def myf(begin,end,a,w,g):
result =0
count= 1000000
delta = (end-begin)/count
for i in range(count):
result += delta*g(begin,a,w)
begin += delta
return result
while(True):
a,w,begin,end = map(float,input().split())
r= myf(begin,end,a,w,f)
print(r),