首页 > 解决方案 > 测试给定问题的整个可能输入范围

问题描述

有没有一种快速的方法可以从函数和相应的参数 x、y 中找到最大值(浮点数),它们都是 0 到 100(含)之间的整数?我是否需要使用 assert 函数或类似的东西来获取所有可能输入的范围?

def fun_A(x,y):
    import math
    if x == y:
       return 0
    first = math.cos((y%75)*(math.pi/180))
    second = math.sin((x%30)*(math.pi/180))
    return (first + second) / (abs(x - y))

标签: python

解决方案


我会为 tan 函数执行此操作:

from math import tan
y = 0
x = 0
for x_iteration in range(0, 101):
    if tan(x_iteration) > y :
        x = x_iteration
        y = tan(x_iteration) 

x = int(x) 
y = int(y) 

推荐阅读