Re[2]: [Tutor] <TUTOR>My first (er...working...) script ever

Gonçalo Rodrigues op73418@mail.telepac.pt
Sun Feb 23 22:41:01 2003


----- Original Message -----
From: "Anna Ravenscroft" <revanna@mn.rr.com>
To: <tutor@python.org>
Sent: Sunday, February 23, 2003 3:36 AM
Subject: Re: Re[2]: [Tutor] <TUTOR>My first (er...working...) script ever


> On Saturday 22 February 2003 21:32, Anna Ravenscroft wrote:
> > On Saturday 22 February 2003 20:57, Predrag Ivanovic wrote:
> > > Something like this,maybe?
> > > ----------------
> > > choice="o"
> > > while choice !="e":
> > >       if choice =="k":
> > >          r=int(raw_input("r:"))
> > >          print "whatever ",krug(r)
> > > ---------------------------------
> > > How    do   i   evaluate  value  and  raise  an  exception  if  input
is
> > > ,for instance,"church police" instead of "42"?
>
> Oops! Make that:
>
> > r = raw_input("r:")
> > try:
> > newr = int(r)
> > print "whatever ",krug(newr)"
> > except:
> > print "That is not a number. "
>

A little better

r = raw_input("r:")
try:
    newr = int(r)
#Catch specific exception.
except ValueError:
    print "That is not a number"
#Move print out of try block.
print "whatever ", krug(newr)

> Just my $.03 worth...
> Anna

With my best regards,
G. Rodrigues