![]() |
How can i restrict the number of characters in an input? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How can i restrict the number of characters in an input? (/thread-10490.html) |
How can i restrict the number of characters in an input? - kevencript - May-23-2018 Hello, world! So, i wanna restrict the number of characters in an input, for exemple: num1 = int(input("Type your age: ")) #here i want the user can only type 3 or < characters RE: How can i restrict the number of characters in an input? - micseydel - May-23-2018 If I were going to do this, I'd check the length of the return value of input() (or the size of num1) and then re-prompt the user on rejection. If you are really serious about limiting the number of typed characters... I'm not as sure. I'd look at the curses module, or consider a GUI of some kind (likely a web server, like Flask, or Kivy since it would be easier to get working on Android). Other options would be platform-specific, which you might be fine with but I wouldn't be sure how to go about it. |