0
def isArmstrongNumber(n):
    a = []
    t = n
    while t > 0:
        a.append(t % 10)
        t /= 10
    l = len(a)
    return sum([x ** l for x in a]) == n 

for x in range(100,1000):
    if isArmstrongNumber(x):
        print(x)

============================= That's an about ArmstrongNumber's question,when I F5 this code,it's show me OverflowError:int too large to convert to float. SO,what can I do to solve this? Ps:I run it with python3.5 enter image description here

Crz_Pepper
  • 1
  • 1
  • 2

1 Answers1

2

Python supports integers of arbitrary size but also uses floating point numbers. There are some integers that are far too big to accurately be represented by floating point numbers, which is why you get your error.

Replace /= with //= to use floor division (which returns an integer) instead of "true" division (which returns a float), since that is what t /= 10 is supposed to do in your loop.

Blender
  • 289,723
  • 53
  • 439
  • 496