Error Testing

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Oct 19 08:37:01 EDT 2013


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




More information about the Python-list mailing list