<jupyter_start><jupyter_text>Input ValidationInput validation code verifies that user supplied data, such as text from the input() function, is formatted appropriately.* try/except* isdigit()* pyinputplus try/except<jupyter_code>while True:
  try:
    integer = int(input ("Please enter your age (integer): ") )
    break
  except ValueError:
    print ("Please enter as integer")
    
prompt = "Please enter your age (integer): "
prompt2 = "Please re-enter as integer"
print (integer)
print ('Let us try again')

valid = False
while not valid:   
  try:
    integer = int( input(prompt) ) 
    # no need to break
    valid = True    # this is earsier to understand than "while True", as it can avoid using break
  except ValueError:
    print (prompt2)

print(integer, 'is an integer.')<jupyter_output>Please enter your age (integer): 1
1
Let us try again
Please enter your age (integer): 10
10 is an integer.<jupyter_text>isdigit()<jupyter_code>valid = False
while not valid:
  integer = input(prompt)
  if integer.isdigit():
    valid = True
  else:   
    print (prompt2)

print(integer, 'is an integer.')<jupyter_output>Please enter your age (integer): 4
4 is an integer.<jupyter_text>Module: pyinputs<jupyter_code>!pip install PyInputPlus



import pyinputplus as pi
num1 = pi.inputNum('Please enter your age (decimal point is allowed):')

print (num1, 'is a number')<jupyter_output>Please enter your age (decimal point is allowed):4.5
4.5 is a number
StarcoderdataJupyterStructuredCleanDedup