0

t ask the user for input and when they type letters it comes up with an error message (as i want) but even when user enters number it comes up with error. I want it to come out of this loop and on to next for name if correct data is inputed.

AChampion
  • 29,683
  • 4
  • 59
  • 75
Programmer
  • 35
  • 7
  • 1
    Read the [input() docs](https://docs.python.org/3/library/functions.html#input). That function always returns a string, not an integer. – skrrgwasme Jan 19 '16 at 19:56

2 Answers2

5

input always returns text - even there are only digits.

Use int(Telephone) to convert to integer or Telephone.isdigit() to check if there are only digits in text.


BTW: both methods are useless if user use spaces or - in phone number ;)

Maybe you will have to remove spaces and - using replace() before you use int() or isdigit()

furas
  • 134,197
  • 12
  • 106
  • 148
3

You need to convert to an int:

while True:
    try:
        Telephone = int(input("Please enter your telephone number "))
        break
    except ValueError:
        print ("Sorry, system does not recognise input ")
AChampion
  • 29,683
  • 4
  • 59
  • 75