the button of cancel

Ben Bush pythonnew at gmail.com
Sun Nov 13 15:02:16 EST 2005


On 11/13/05, Fredrik Lundh <fredrik at pythonware.com> wrote:
>
> Ben Bush wrote:
>
> > When I click the button of cancel,
> > I got the follwoing message. I want to see "Goodbye" on the console
> screen.
> > What to do?
>
> > KeyboardInterrupt: operation cancelled
>
> > num = input( "Enter a number between 1 and 100: " )
> > while num < 1 or num > 100:
> > print "Oops, your input value (", num, ") is out of range."
> > num = input( "Be sure to enter a value between 1 and 100: " )
>
> you need to catch the exception, and print the message you want.
>
> try:
> ... your code ...
> except KeyboardInterrupt:
> print "Goodbye!"
>
> see chapter 8.3 in the tutorial for more info:
>
> http://docs.python.org/tut/node10.html
>
> </F>
> Thanks, now the code works. I wonder when i put the number between 1 and
> 100, I get the message of 'Your number is in the range' but i still see the
> input box. How to remove it?
> num = input( "Enter a number between 1 and 100: " )
> try:
> while num < 1 or num > 100:
> print 'Oops, your input value (', num, ') is out of range.'
> num = input( 'Be sure to enter a value between 1 and 100: ' )
> num=input('Your number is in the range')
> except KeyboardInterrupt:
> print 'Goodbye!'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051113/9c16a222/attachment.html>


More information about the Python-list mailing list