python - I want to calculate are of parallelogram only if vertices lie between 0 to 1000 ,i.e. 0<=x<1000. How can I define constraints?
问题描述
How can I define constraints in python? I want to calculate are of parallelogram only if vertices lie between 0 to 1000 ,i.e. 0<=x<1000.
解决方案
For me, the best method is to throw an exception inside your function. For example :
def yourFunction(x):
if(0<=x<1000):
raise SyntaxError("Please provide a correct value")
pass # your code here
推荐阅读
- rust - 如何在编译时检查切片是否具有特定大小?
- amazon-ec2 - 如果我可以使用 EC2 自动扩展组部署多服务 docker 容器,为什么还要使用 AWS ECS?
- swift - 如何为 Reality Composer 安装手势?
- kubernetes - Argo Workflows pod 缺少 cpu/内存资源
- python - 如何提取这样的锚标签?
- python - Python 脚本启动 - Debian
- html - BeautifulSoup:如何从下面的代码中获取内容属性?
- python - pathlib 获取基本路径,给定绝对路径和相对路径
- reactjs - 当 React App 尝试通过 SignalR 连接到启用了 Windows 身份验证的 .NET CORE Web App 时出现 CORS 错误
- python - 如何在pyqt中使QRadioButton圆圈变粗?