Oops, I sent this to Roelof... Ok, I must amend it anyway...

On 10/09/2010 17.13, Roelof Wobben wrote:
...
def readposint():
        x = raw_input("Please enter a positive integer :")
        try:
                x = int(x) and x>  0
        except:
                print x , "is not a positive integer.    Try again."
                return False
        return True

y = readposint()
print y
while y == False:
        readposint()
print "You have entered : ", y

But the x>  10 is never checked.

Must I use two try except now ?
Your first problem has nothing to do with exception handling.
The culprit is Line 4:
                x = int(x) and x>  0
I suppose that you forgot a second equal sign between x and int(x). If it were
               x == int(x) and x > 0
it would have worked as expected. But this would not trigger any exception, if X is a number. So let's add one:
>                if not (x == int(x) and x > 0): raise(ValueError)

Hope that helps,

Roelof
Francesco
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3124 -  Data di rilascio: 
09/09/10 08:34:00
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to