0
def input_base():
    print('please enter the number')
    base = input("Number : ")
    while not base.isdigit():
       print("It`s not integer")
       base = input("R.Number : ")
    return base 
    ...

This is my code and the error is:

AttributeError : 'int' object has no attribute 'isdigit'

I don't know how I could fix this code. I think, I should install some application, such a python-numpy, inside Ubuntu...
Is that right?

zx485
  • 28,498
  • 28
  • 50
  • 59
orde.r
  • 521
  • 2
  • 5
  • 13

1 Answers1

0

You are using python2 therefore you have two functions input and raw_input. The difference being that input calls eval on the inputted string. This turns it from a string to whatever python would interpret it as when input as a script or at the REPL.

For the input 1 you would get the int value 1.

So the value you now have is an int and not a string. It does not have a method isdigit. If you are sticking with python 2, you should instead use raw_input, which doesnt do the eval and therefore always returns a string, which has an isdigit method.

For python3 input does what raw_input does it py2 and so works correctly here.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61