Bug asking for input number
a7xrturodev at gmail.com
Sat Nov 16 03:15:36 CET 2013
Hi! I hope you can help me.
I'm writting a simple piece of code.
I need to keep asking for a number until it has all this specifications:
- It is a number
- It's lenght is 3
- The hundred's digit differs from the one's digit by at least two
My problem is that I enter a valid number like: 123, 321, 159, 346... and it keeps asking for a valid number.
Here's mi code:
res = input('Give me a number --> ')
hundreds = int(res)
ones = int(res)
# checks if the user enters a valid number
while not res.isdigit() or not len(res) == 3 or abs(hundreds - ones) <= 2:
res = input('Enter a valid number --> ')
Thanks for help!
More information about the Python-list