Error Testing

Scott Novinger scnovinger at gmail.com
Sat Oct 19 09:34:30 EDT 2013


On Saturday, October 19, 2013 8:37:01 AM UTC-4, Mark Lawrence wrote:
> On 19/10/2013 13:23, Scott Novinger wrote:
> 
> > Hello.
> 
> >
> 
> > I've written a program for my kids to calculate arc length.  I want to include some error testing for value types entered that are something other than integer values.
> 
> >
> 
> > My goal is to make sure that the value entered for the radius is an integer value.
> 
> >
> 
> > How could I rewrite this code to make sure I accomplish my goal of getting an integer value entered?  I know the construct is not correct.  I'm just learning how to program.
> 
> >
> 
> >      # Create the variable for radius, "radius".
> 
> >      print('Please enter the circle radius and press ENTER:')
> 
> >      radius = input()
> 
> >
> 
> >      # Check to make sure the entered value is an integer.
> 
> >      if type(radius) != type(int):
> 
> >          print('You must enter an integer value.')
> 
> >          print('Please enter the circle radius and press ENTER:')
> 
> >          radius = input()
> 
> >      else:
> 
> >          print('The radius you entered is: ' + radius)
> 
> >
> 
> >      radius = int(radius)
> 
> >
> 
> > Thanks for your help. I'm using Python v3.2 for windows.
> 
> >
> 
> > Scott
> 
> >
> 
> 
> 
> Please see the example here 
> 
> http://docs.python.org/3/tutorial/errors.html#handling-exceptions.  If 
> 
> you want further data feel free to ask, we don't bite :)
> 
> 
> 
> -- 
> 
> Roses are red,
> 
> Violets are blue,
> 
> Most poems rhyme,
> 
> But this one doesn't.
> 
> 
> 
> Mark Lawrence

Mark/ All,

I read the link on Handling Exceptions.  The first bit of code worked for my purposes. I was able to reduce my number of lines of code significantly and my program works! Thank you all for your help solving this problem!

My plan is to create several different programs that perform specific Algebraic operations.  My boys are learning Algebra 2 and I thought it might be a fun way to help us all learn Algebra and programming together.  Python seems to be a good language for learning how to program.

Thanks again!

Scott



More information about the Python-list mailing list