[Tutor] exceptions

Diana Hawksworth dianahawks at optusnet.com.au
Sat Apr 16 04:25:55 CEST 2005


Hello list,

I have been trying to trap a string entry by raising an exception.  The code follows - but the exception is never raised.  What am I doing wrong?

TIA Diana

 try:
            
            self.guess = int(self.num_ent.get())

            self.num_ent.delete(0,END)
            self.num_ent.focus_set()
        
            
            if self.guess < self.number:            
                message = str(self.guess) + " is too low. You need to guess higher"

            if self.guess > self.number:      
                message = str(self.guess) + " is too high. You need to guess lower"
            
            if self.guess == self.number:
                message = str(self.guess) + " is the correct number!"
                self.message_txt.config(state = NORMAL)
                self.message_txt.config(state = DISABLED)
        
            self.message_txt.config(state = NORMAL)
            self.message_txt.delete(0.0, END)
            self.message_txt.insert(0.0, message)
            self.message_txt.config(state = DISABLED)


 except(ValueError):
         message = str(self.guess) + " is not a number. Please try again!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050416/db143c3e/attachment.html


More information about the Tutor mailing list