Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57097
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'interpreter': 0.05; 'string.': 0.05; 'subject:Error': 0.07; 'literal': 0.09; 'type,': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'windows': 0.15; 'failure.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer,': 0.16; 'integer.': 0.16; 'string:': 0.16; '(you': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'entered': 0.20; 'work,': 0.20; 'help.': 0.21; '>>>': 0.22; 'error': 0.23; 'integer': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; '"",': 0.31; 'block,': 0.31; 'file': 0.32; 'there.': 0.32; 'probably': 0.32; '(most': 0.33; 'checking': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'idle': 0.36; 'thanks': 0.36; 'turn': 0.37; 'easily': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'recent': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'conversion': 0.61; "you're": 0.61; 'circle': 0.68; 'invalid': 0.68; 'line,': 0.68; 'default': 0.69; 'press': 0.70; '10:': 0.84; 'effectively,': 0.84; 'fails,': 0.84; 'subject:Testing': 0.84; 'succeed.': 0.84; 'want:': 0.84; 'scott': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=A2FdGLVDHeLN/tjYFixTLmg5/pb4OCDyIfetx7FYjZ0=; b=sBrlMoHzaTG1Hptr5qin+G8t3STfGRi8pFUDcgREx6/6gxR0DgvXj9F7cNm2r3KIoQ T9hBtK7/wozBEQ802+kB61J0VI/UaiCgh5GGmbmL+AEFHS0AaxIJ6mOYNLaE/i1l/0kD cdU3xvz2Bbav4CiN6uZ8pYTGoFQAKfmIydSEL1aI1reC6kI4PMh9IfH23SVI0mX+bl+N WI4a3bp8N+aWW6o89zmwc4YULWHjmAqJK0Aw2oVMxFSZRmz7AVT9p3Q0BwHpgDHb/t2U 4XOXLsAis8561KFd6qaacK78b4s6YaQfCAcsFk6NX7Gj6pyAMoYmYCGrDMh1s4P6PIcV pDyw== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.48.166 with SMTP id m6mr7942247pbn.105.1382187688844; Sat, 19 Oct 2013 06:01:28 -0700 (PDT) |
| In-Reply-To | <33549834-2f27-47f3-abea-eb3486909dec@googlegroups.com> |
| References | <33549834-2f27-47f3-abea-eb3486909dec@googlegroups.com> |
| Date | Sun, 20 Oct 2013 00:01:28 +1100 |
| Subject | Re: Error Testing |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1255.1382187698.18130.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1382187698 news.xs4all.nl 15878 [2001:888:2000:d::a6]:49281 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:57097 |
Show key headers only | View raw
On Sat, Oct 19, 2013 at 11:23 PM, Scott Novinger <scnovinger@gmail.com> wrote:
> # 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.
In Python 3, the input() function always returns a string. Your type
check is never going to succeed. Also, you're not checking what you
think you're checking; you're actually looking to see if input()
returned a type, because the type of int is type:
>>> type(int)
<class 'type'>
You might want:
if type(radius) != int:
But that still won't work, because input() will always return a string:
>>> radius = input()
42
>>> type(radius)
<class 'str'>
You can try all these out in the interactive interpreter (you probably
have IDLE installed, which on Windows is rather nicer to work with
than the default interactive mode).
A better check would be to just try to turn the inputted value into an
integer, and fail if that doesn't work. Again, try this interactively:
>>> int("42")
42
>>> int("not an integer")
Traceback (most recent call last):
File "<pyshell#58>", line 1, in <module>
int("not an integer")
ValueError: invalid literal for int() with base 10: 'not an integer'
With a couple of quick checks, you can easily see what happens if the
conversion fails, and then you can deal with that failure. So
effectively, just drop the whole if: block, go straight to the "radius
= int(radius)" line, and deal with the error there.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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