python - 如何在数学函数中使用下一个乘法数
问题描述
当用户输入 6 时,我有一种情况,例如 a=14,然后它将被检查为乘法数的下一个最大数。
if 6*2>14 so not working and then that 6*3>14 so it is working.
我不知道数学函数的名称是什么。
解决方案
我想你只是想要:
factor = ((a-1) // n + 1)
像 14 这样的数字在哪里a
,而 n 是要乘以 的较小数字factor
:
a = 15
n = 7
factor = ((a-1) // n + 1)
print("factor", factor)
# 3
print("multiplied:", n * ((a-1) // n + 1))
# 21
从您的问题中不清楚完全匹配会发生什么,但这将返回确切的因素:
a = 14
n = 7
factor = ((a-1) // n + 1)
print("factor", factor)
# 2
print("multiplied:", n * ((a-1) // n + 1))
#4
推荐阅读
- python - 将2个数据框与熊猫中的不同列合并
- java - 在 Java 中使用 base64 编码的 HTTP/1.1 400 错误请求
- .net-core - Entity Framework Core 从 2.2 迁移到 3.1:更新外键对象不起作用
- javascript - 我真的应该拥有所有这些“这个”吗?在我的班级内所有变量?
- python-3.x - Google App Engine 请求日志,包括严重性
- vue.js - 这种方法对于在 Vuejs 的 watch 中从异步方法接收更新是否正确?
- spring-boot - Spring cloud Sleuth 开始一个新的跟踪,而不是在单个跟踪中继续跨越
- azure - 有没有办法让 Azure devops(构建)管道等待 x 分钟来收集/组合多个批准的 PR?
- php - 用正则表达式动态替换条件块的一部分
- laravel - 数据表添加按列搜索会改变表的大小