1

I have one case like a=14 when the user enters 6 then it will be check as next largest number of the multiplication number.

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

I have no idea what was the name of the math function.

Harshit Trivedi
  • 764
  • 9
  • 33

4 Answers4

2

I think you just want:

factor = ((a-1) // n + 1)

Where a is you number like 14 and n is the smaller number to be multiplied by the factor:

a = 15
n = 7
factor = ((a-1) // n + 1)
print("factor", factor)
# 3
print("multiplied:", n * ((a-1) // n + 1))
# 21

it's not clear from your question what happens with an exact match, but this will return the exact factor:

a = 14
n = 7
factor = ((a-1) // n + 1)
print("factor", factor)
# 2
print("multiplied:", n * ((a-1) // n + 1))
#4
Mark
  • 90,562
  • 7
  • 108
  • 148
1

This is my guess on what is meant based on the other comments:

user_number= int(input("What is your number? "))

check_number=int(input("What is the number to check against. "))

factor = 1
print(check_number, factor*user_number)
while(check_number>(factor*user_number)):
    print(factor)
    print("Not working.")
    factor+=1

working_factor = check_number%user_number+1
print("using modulo: ", working_factor)
print("Working factor: ",factor)

Output: enter image description here

Richard K Yu
  • 2,152
  • 3
  • 8
  • 21
1
import math
a = 14
b = 6
mutiple = math.floor(a/b)+1
value = mutiple*b

print (mutiple, value)
mujjiga
  • 16,186
  • 2
  • 33
  • 51
1

You can use math.ceil to calculate the ceiling of number/multiplier and multiply with it multiplier to get your result

import math

def func(number, multiplier):
    return multiplier * math.ceil(number/multiplier)

The output will be

print(func(14,6))
#18
print(func(18,6))
#18
print(func(19,6))
#24

Example for number=14 and multiplier=6, math.ceil(14/6) gives 3, and 6*3 gives 18

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40