Answer the question
In order to leave comments, you need to log in
How to determine that the data entered by the user is a number?
a = int(input('Your age > '))
If the user enters characters that are not numbers, then an error will occur because the variable is int. It is necessary that when the user writes any data that is not a number, a certain code occurs, and not an error.
Answer the question
In order to leave comments, you need to log in
In Python, input() returns a string. A string has many methods, some of them are checking the string for belonging to one or another type of character. One such method, .isdigit() returns a boolean whether the string contains only digits. You can use this method to validate entered characters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question