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个数,可计算出来结果。
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),