Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37742
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.020 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'debugging': 0.05; 'strings.': 0.07; 'valueerror:': 0.07; 'literal': 0.09; 'subject:python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'integers,': 0.16; 'least,': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'thus': 0.24; 'header:In-Reply- To:1': 0.25; 'common': 0.26; '(most': 0.27; 'am,': 0.27; 'guess': 0.27; 'message-id:@mail.gmail.com': 0.27; 'division': 0.29; 'probably': 0.29; 'file': 0.32; 'comments': 0.33; '11,': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'skip:p 20': 0.36; 'display': 0.36; 'turn': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'space': 0.39; 'skip:" 10': 0.40; 'end': 0.40; 'your': 0.60; 'gas': 0.81; '2013': 0.84; 'on?': 0.91; 'subject:looking': 0.91; 'this;': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=me7dshGj2XnWQz92vL0XCufLwa2TM+do14H7Ca3RbNE=; b=FKR/SQMVS7rtloNBjVXXf4LSjAzkEfhd+8N8Hec2P2kQOcBqexrDJmIpb96fiwxgSe EmuFIy5OWmNub7YyZrcBQWvCi/wK5VgofXHGiJ9vAcSJ4TrfpxhllYHdln2627OsPWtC /8IFOQxwpL8M075tP6Qpdq4p5M8cD7tbEx6AHg2CwFacDrLkTEJ+4MEuJ3wSU5pRpIo6 UYrkpAY+OLxXtBy9BzIH0klx+6P5V9moHdKE0VvAsPV4So3ndlNkgkZqEH3/C/8rI3uL XTGEv0PwmeMirnh+yrK8AQuKgtEXRtAL0HekS66n/GClQ19xYyims1WckJaVG5VrCZRL PzDg== |
| MIME-Version | 1.0 |
| X-Received | by 10.221.11.205 with SMTP id pf13mr10375266vcb.70.1359240481241; Sat, 26 Jan 2013 14:48:01 -0800 (PST) |
| In-Reply-To | <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> |
| References | <39d427b2-f5d7-4bd9-99f8-8cfd8d25b3cc@googlegroups.com> |
| Date | Sun, 27 Jan 2013 09:48:01 +1100 |
| Subject | Re: looking for advice python |
| 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 | <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.1091.1359240489.2939.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359240489 news.xs4all.nl 6934 [2001:888:2000:d::a6]:46347 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37742 |
Show key headers only | View raw
On Sun, Jan 27, 2013 at 9:26 AM, <twiztidtrees@gmail.com> wrote:
> miles = int(string_miles)
> gas = int(string_gas)
>
> #used to calculate mpg through division
> mpg = miles/gas
>
> print(float(string_miles))
> print(float(string_gas))
> print('Your miles per gallon is', format(mpg,'.2f'))
Welcome aboard!
You turn your inputs into integers, then display them as floats...
from the original strings. (Though I guess this is probably debugging
code?) I would advise against doing this; at very least, it's
confusing. I would recommend simply using floats everywhere, and thus
allowing non-integer inputs:
How many miles did you drive?60.9
How many gallons of gas did you use?11.9
Traceback (most recent call last):
File "123.py", line 11, in <module>
miles = int(string_miles)
ValueError: invalid literal for int() with base 10: '60.9'
Small additional point: It's common to put a space at the end of your
prompt, to avoid the "crammed" look of "drive?60.9".
Are there any particular areas that you'd like comments on?
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
looking for advice python twiztidtrees@gmail.com - 2013-01-26 14:26 -0800
Re: looking for advice python Chris Angelico <rosuav@gmail.com> - 2013-01-27 09:48 +1100
Re: looking for advice python Dave Angel <davea@davea.name> - 2013-01-26 18:00 -0500
Re: looking for advice python twiztidtrees@gmail.com - 2013-01-27 10:57 -0800
Re: looking for advice python twiztidtrees@gmail.com - 2013-01-28 13:59 -0800
csiph-web