On 11/15/2013 9:15 PM, Arturo B wrote:
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.

If you enter a 'valid' number at first try, it works fine.

Here's mi code:

res = input('Give me a number --> ')
hundreds = int(res[0])
ones = int(res[2])

# checks if the user enters a valid number
while not res.isdigit() or not len(res) == 3 or abs(hundreds - ones) <= 2:

Look at that last condition *carefully*!!!!

     res = input('Enter a valid number --> ')


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to