Question

a = 218500000000

s = 6
f = 2
k = 49
d = k + f + s

r = a
i = 0

while (r >= d):
  r = r - d
  #print ('r = ',r)
  i = i+1
  #print ('i = ',i)

print (i)

I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while python used 100% cpu to calculate..), but it didn't. Is there a more efficient way of rewriting this piece of code so I can see how many iterations (i) it takes to complete?

Many thanks

Was it helpful?

Solution

r = (a % d)
i = (a / d)

Use the modulo and division operators.

There is also a divmod function to calculate both together:

i, r = divmod(a,d)

OTHER TIPS

You can use i = a/d. :D

Isn't a division what you're looking for?

try 3833333333.3333333333333333333333. AKA r / d.

Looks like you are doing truncating division to me. That is, you want to find out how many times d goes into a without knowing the remainder.

a = 218500000000
s = 6
f = 2
k = 49
d = k + f + s

i = a // d

print (i)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top