0

I'm writing a simple program to accept only numbers. but the program is accepting both letters and numbers

I'm using python 3.. I used the int data type in addition to input statement.

#A program to accept input of a number
print('Welcome to our age verification system.')
int(input('Enter your age: '))

I expected it to accept only integers.

Simeon Udoh
  • 23
  • 1
  • 4

2 Answers2

1

You can judge your input is a digit first.

#A program to accept input of a number
print('Welcome to our age verification system.')
input_string = input('Enter your age: ')
if input_string.isdigit():
    print(int(input_string))
else:
    print("please input a number")
everfight
  • 420
  • 3
  • 10
0

Is a duplicate of this question

try:
    int(input('Enter your age: '))
except ValueError:
    print('This isn\'t a number');
ShiSHcat
  • 83
  • 1
  • 8