decipher
decipher

Reputation: 498

floating point number in iterator

i am trying to run an iteration which goes upto a floating point number. Unfortunately, the iteration variable is an integer. i want to know how can fix this problem. here is the code snippet:

for it in range(num_iters):
      if it % 10 == 0:  print ('starting iteration ', it)

the value for num_iters is floating point. the error i am getting getting is:

---> 69     for it in range(num_iters):
     70       if it % 10 == 0:  print ('starting iteration ', it)
     71 

TypeError: 'float' object cannot be interpreted as an integer

Upvotes: 0

Views: 64

Answers (1)

Hearner
Hearner

Reputation: 2729

Just use range(int(round(num_iters))):

Upvotes: 1

Related Questions