Graphics Entry problem

1 view
Skip to first unread message

ajf1703

unread,
May 18, 2009, 9:39:04 PM5/18/09
to Charlotte Python Group
I need to know specifically how to word my program so that when an
Entry value is invalid (aka not a number) the program won't crash but
instead just ask for another entry
Thank You

Calvin Spealman

unread,
May 19, 2009, 7:06:13 AM5/19/09
to cha...@googlegroups.com
value = input_raw("What is the number?")
while not isinstance(value, int):
try:
value = int(value)
except ValueError:
value = input_raw("What is the number?")

In other words, get the text input, and then keep trying to convert it
to an int while asking for input again if that conversion fails. Stop
trying this when `value` is seen to be an integer.
--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
Reply all
Reply to author
Forward
0 new messages