Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python input integer

# To prompt the user to input an integer we do the following:
valid = False

while not valid: #loop until the user enters a valid int
    try:
        x = int(input('Enter an integer: '))
        valid = True #if this point is reached, x is a valid int
    except ValueError:
        print('Please only input digits')
 
PREVIOUS NEXT
Tagged: #python #input #integer
ADD COMMENT
Topic
Name
1+7 =