Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57102

Re: Error Testing

Newsgroups comp.lang.python
Date 2013-10-19 06:34 -0700
References <33549834-2f27-47f3-abea-eb3486909dec@googlegroups.com> <mailman.1253.1382186251.18130.python-list@python.org>
Message-ID <ea2d79c5-e116-458f-a77c-700e748323e2@googlegroups.com> (permalink)
Subject Re: Error Testing
From Scott Novinger <scnovinger@gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Error Testing Scott Novinger <scnovinger@gmail.com> - 2013-10-19 05:23 -0700
  Re: Error Testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-19 13:37 +0100
    Re: Error Testing Scott Novinger <scnovinger@gmail.com> - 2013-10-19 06:34 -0700
      Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 00:42 +1100
      Re: Error Testing rusi <rustompmody@gmail.com> - 2013-10-19 09:22 -0700
        Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 09:28 +1100
        Re: Error Testing Ned Deily <nad@acm.org> - 2013-10-19 15:46 -0700
        Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 10:02 +1100
        Re: Error Testing Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-20 12:18 -0400
  Re: Error Testing Ned Batchelder <ned@nedbatchelder.com> - 2013-10-19 08:44 -0400
    Re: Error Testing Roy Smith <roy@panix.com> - 2013-10-19 08:57 -0400
      Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 00:04 +1100
      Re: Error Testing Ned Batchelder <ned@nedbatchelder.com> - 2013-10-19 09:07 -0400
        Re: Error Testing Roy Smith <roy@panix.com> - 2013-10-19 09:09 -0400
      Re: Error Testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-19 14:19 +0100
  Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 00:01 +1100
  Re: Error Testing David Robinow <drobinow@gmail.com> - 2013-10-19 14:08 -0400
  Re: Error Testing Tim Chase <tim@thechases.com> - 2013-10-19 13:31 -0500
  Re: Error Testing Terry Reedy <tjreedy@udel.edu> - 2013-10-19 15:50 -0400
  What's wrong with Windows Command Prompt (was Re: Error Testing) Terry Reedy <tjreedy@udel.edu> - 2013-10-19 16:35 -0400
  Re: What's wrong with Windows Command Prompt (was Re: Error Testing) Chris Angelico <rosuav@gmail.com> - 2013-10-20 09:15 +1100
  Re: Error Testing Chris Angelico <rosuav@gmail.com> - 2013-10-20 09:20 +1100
  Re: What's wrong with Windows Command Prompt (was Re: Error Testing) David Robinow <drobinow@gmail.com> - 2013-10-21 15:55 -0400
  Re: What's wrong with Windows Command Prompt (was Re: Error Testing) Tim Chase <python.list@tim.thechases.com> - 2013-10-21 15:29 -0500

csiph-web