python - 测试给定问题的整个可能输入范围
问题描述
有没有一种快速的方法可以从函数和相应的参数 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))
解决方案
我会为 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)
推荐阅读
- ios - 仅在 iPad 上长按时,在列表中加载更多内容的 NavigationView 崩溃
- c++ - IntRect SFML 声明
- django - 无法更改超级用户自己的 django admin inline
- jquery - Jquery 脚本中带有 fontawesome 图标类的 Span 元素自动被 SVG 替换?奇怪的行为
- perl - 在 perl 中从系统命令中捕获退出代码
- python - 将 Pandas 系列转换为没有索引的字典
- python - 如何使点文件夹/文件统一可见?
- html - 圆角和容器的问题
- firebase - 嵌套的 firebase-firestore 规则:父文档中的所有者 ID
- hibernate - 如何在休眠中将实体正确映射到多个实体类型?