首页 > 解决方案 > 如何在数学函数中使用下一个乘法数

问题描述

当用户输入 6 时,我有一种情况,例如 a=14,然后它将被检查为乘法数的下一个最大数。

if 6*2>14 so not working and then that 6*3>14 so it is working. 

我不知道数学函数的名称是什么。

标签: pythonpython-3.xmath

解决方案


我想你只是想要:

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

推荐阅读