I try to validate user input if is integer not in a function.
while True:
try:
number = int(input('Enter the number: '))
except ValueError:
print('Try again. Input phone number, must containing digits. ')
break
print (number)
If I enter number it works prints the number (however Pycharm tells me that variable number in last line might ve undefined) however when it crash instead asking for enter again:
Enter the number: s
Try again. Input phone number, must containing digits.
Traceback (most recent call last):
line 9, in <module>
print (number)
NameError: name 'number' is not defined
In a function it seems easier to make but in this case I'm lost.