Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46747
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <drsalists@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.032 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'exercise': 0.04; 'string': 0.09; '")': 0.09; 'get.': 0.09; 'literal': 0.09; 'subject:string': 0.09; 'valueerror:': 0.09; 'cc:addr:python- list': 0.11; '23,': 0.16; 'cc:name:python list': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'subject:Issue': 0.19; 'input': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'skip:p 30': 0.29; "doesn't": 0.30; 'converting': 0.30; 'skip:& 60': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'second,': 0.31; 'skip:! 10': 0.31; 'file': 0.32; '(most': 0.33; 'skip:s 30': 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:" 50': 0.36; 'hi,': 0.36; 'two': 0.37; 'skip:& 10': 0.38; 'version,': 0.38; 'pm,': 0.38; 'rather': 0.38; 'recent': 0.39; 'bad': 0.39; 'changed': 0.39; 'blank': 0.60; 'conversion': 0.61; "you're": 0.61; 'first': 0.61; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'invalid': 0.68; 'line,': 0.68; '10:': 0.84; 'non-empty.': 0.84; 'partial': 0.84; '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 :cc:content-type; bh=XPuqChF+ydQbIzx7U9k25fH2KupC1ej0UtaWPpk2YZc=; b=irw9g1LF56EnouJx4S05qN7Uurw94p70artHEyVMbjRWHh1pvSaEcnTFxc2k1TqEn7 cXfuRTDVEoRenYZpUbnSYteKL1kKwiGAZQm0eJO32MVBYrjm/OKWNNEJPTfZdj8RZ12Q TooLdTwqY+rPV5M9JwncGyVdxdzneOGBWHfwLo6sX1BZKmMiZEuNi8Z5zc5hEzhb2qyz l8NE5EDhCE9hFOlBMB2WHS5nQp4UN64FHPMJuzNwAU0BCXzFcId+hP/r3xj/k7eWbOHD Uo026BK2m7XFL4i2HQYx9IKuv7qmtX7A5V48kCr3a53sGbTGWrk+hZZNDyQBAggulbY6 9PiA== |
| MIME-Version | 1.0 |
| X-Received | by 10.229.11.199 with SMTP id u7mr7028246qcu.42.1370223842451; Sun, 02 Jun 2013 18:44:02 -0700 (PDT) |
| In-Reply-To | <55c2eb06-7b9f-480f-8668-5e19e236799f@googlegroups.com> |
| References | <55c2eb06-7b9f-480f-8668-5e19e236799f@googlegroups.com> |
| Date | Sun, 2 Jun 2013 18:44:02 -0700 |
| Subject | Re: Issue converting to string to integer. |
| From | Dan Stromberg <drsalists@gmail.com> |
| To | Fdama <fsdama@gmail.com> |
| Content-Type | multipart/alternative; boundary=001a11c3fecc6489d904de361941 |
| Cc | Python List <python-list@python.org> |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2570.1370223845.3114.python-list@python.org> (permalink) |
| Lines | 112 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370223845 news.xs4all.nl 15930 [2001:888:2000:d::a6]:43503 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46747 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Sun, Jun 2, 2013 at 6:12 PM, Fdama <fsdama@gmail.com> wrote:
> Hi,
>
> I was following an exercise in a book when I edited the code and came
> across something I did not get. Here is the relevant part of the code that
> works:
>
> start=None #initialise
> while start !="":
> start=input("\nStart: ")
>
> if start:
> start=int(start)
> finish=int(input("Finish: "))
>
> print("word[",start,":",finish,"] is", word[start:finish])
>
> I then changed the code to this:
>
> start=None #initialise
> while start !="":
> start=int(input("\nStart: "))
>
> if start:
>
> finish=int(input("Finish: "))
>
> print("word[",start,":",finish,"] is", word[start:finish])
>
> I combined the int conversion and the input on the same line, rather than
> to have two different statements. But got an error message:
>
> Traceback (most recent call last):
> File "C:\Users\Faisal\Documents\python\pizza_slicer.py", line 23, in
> <module>
> start=int(input("\nStart: "))
> ValueError: invalid literal for int() with base 10: ''
>
Converting an empty string to base 10 doesn't fly, so if you hit a blank
line on the input(), you get a bad conversion. In the first version,
you're only converting to base 10 if the string is non-empty. In the
second, you're attempting to convert irrespective.
BTW, I'm partial to:
if not start:
continue
...but that's a stylistic thing.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Issue converting to string to integer. Fdama <fsdama@gmail.com> - 2013-06-02 18:12 -0700
Re: Issue converting to string to integer. Dan Stromberg <drsalists@gmail.com> - 2013-06-02 18:44 -0700
Re: Issue converting to string to integer. Dan Sommers <dan@tombstonezero.net> - 2013-06-03 01:52 +0000
Re: Issue converting to string to integer. Chris Angelico <rosuav@gmail.com> - 2013-06-03 12:08 +1000
Re: Issue converting to string to integer. alex23 <wuwei23@gmail.com> - 2013-06-02 19:02 -0700
csiph-web