Как поставить проверку на текст который ввел пользователь, т.е как ограничить пользователя чтобв он не смог вводить текст, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Как поставить проверку на текст который ввел пользователь, т.е как ограничить пользователя чтобв он не смог вводить текст,

только чтобы пользователь смог написать числа

4th Sep 2017, 1:19 PM
Русленго
Русленго - avatar
3 Answers
+ 9
gt { How to put a check on the text that the user entered, ie how to restrict the user so that he could not enter text, only to allow the user to write numbers } consider posting in English. use google/bing translate if it's difficult. https://www.sololearn.com/discuss/333866/?ref=app
4th Sep 2017, 1:42 PM
Lord Krishna
Lord Krishna - avatar
0
Ограничить нельзя, но вот проверку сделать можно: i = 0 while i == 0: try: a = int(input()) except: print("Пожалуйста введите числа") i = 1 complete
19th Jan 2018, 5:22 PM
ajans
ajans - avatar
0
Можно регулярными выражениями отрезать всё, что ввёл пользователь. Например, чтобы удалить всё, кроме цифр, используй такой код с "шаблоном": import re user_input = str(input()) pattern = r"[^0-9]" user_output = re.sub(pattern, "", user_input) print(user_output)
27th Jan 2020, 8:01 AM
Valerii Mamontov
Valerii Mamontov - avatar