using python to get to a value with only known numbers

Question:

let’s say I have only have 2 known numbers, 1500 & 1000 and I want to figure out how many of each I need to add to get to 4000. what would be the most efficient way to code that?

Asked By: Jayme McColgan

||

Answers:

floor division, but with only two options, of course there still might be a remainder.

goal = 4000

a = goal // 1500
goal -= a * 1500
b = goal // 1000
goal -= b * 1000

results = {'balance': goal, '1500': a, '1000': b}
for k, v in results.items():
    print(k, ':', v)
Answered By: richard

Here is one way you could do that.

#set variabes
N_1 = 1000
N_2 = 1500
N_3 = 4000
#set answer to how many times number 2 will go into number 3
Answer = N_3 / N_2
print (Answer)
# or you could do this to get number 1 will go into number 3
answer = N_3 / N_1
print (answer)

This will tell you how many times the numbers go into 4000 to change the numbers just set the variable to different values.

Answered By: Will

Solved this based on my situation… this is what worked for me but properly was luck based on the 2 numbers I was using.

goal = 4000
a = goal // 1500
goal -= a * 1500
b = goal // 1000
goal -= b * 1000

if goal == 0:
    threetall = a
    twotall = b

elif goal == 500:
    goal += 1500
    b = goal // 1000

    threetall = a - 1
    twotall = b
Answered By: Jayme McColgan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.