Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66460
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'output': 0.05; '#if': 0.07; 'string': 0.09; 'converted': 0.09; 'python': 0.11; 'anyway': 0.14; '#elif': 0.16; '9.9': 0.16; 'calculator': 0.16; 'commented': 0.16; 'division.': 0.16; 'mega': 0.16; 'res': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'feb': 0.22; 'input': 0.22; 'example': 0.22; 'tests': 0.22; 'print': 0.22; 'integer': 0.24; 'string,': 0.24; 'script': 0.25; '15,': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'explained': 0.31; 'subject:numbers': 0.31; 'class': 0.32; 'probably': 0.32; 'says': 0.33; 'received:google.com': 0.35; 'curious': 0.36; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'number,': 0.60; 'length': 0.61; "you're": 0.61; 'show': 0.63; 'more': 0.64; 'natural': 0.68; 'resistance': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=NDbabi5Gvg8t4dcWpNoO5/oyOpoNbFNeBz4L+2vKS+c=; b=I0K+mknqDMkLqWgV+BGzrAnqDHnHsRmCRUv0Bzgrofb44eBKJMsMpQ3UC4kJfS7PC4 SrT8rp+C9Ztq0jj5zmZJ21EM2VwK/jlS1no+pYoN7d2hnlfpgkIEN/XZ5mi0n2QdoVvh ArwYAyu7WtZI9jmPPx8MHJiACWrsY98pED2K7SjGqC5ThwBkO0gk07Czw6JUtypxryv7 ivx45+Gn3mIqx5RxrjYeNvBrMAkP5qbrVSwO2xFBgUZrfBQraT8fQjWSuoDy5S3Pox+j 4VeTJEQtuhrMjApfLvqIOMVZnjpGilQC1paj8F0gJ1L5pRE3NMYLM6XkjhTNyrUQPPYN jkfQ== |
| X-Received | by 10.68.137.195 with SMTP id qk3mr16449133pbb.9.1392484875644; Sat, 15 Feb 2014 09:21:15 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <833583c7-c307-4ebf-9a60-3be146a565b5@googlegroups.com> |
| References | <833583c7-c307-4ebf-9a60-3be146a565b5@googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Sat, 15 Feb 2014 10:20:35 -0700 |
| Subject | Re: decimal numbers |
| To | Python <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.7010.1392484878.18130.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392484878 news.xs4all.nl 2841 [2001:888:2000:d::a6]:59959 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66460 |
Show key headers only | View raw
On Sat, Feb 15, 2014 at 2:18 AM, <luke.geelen@gmail.com> wrote: > hello, > i have been working on a python resistor calculator to let my class show what you can do with python. > now i have a script that makes the more speekable value of the resistance (res) > > #if len(str(res)) > 9: > # res2 = res / 1000000000 > # print "de weerstand is %s,%s giga ohms" % (res2) > #elif len(str(res)) > 6: > # res2 = res / 1000000 > # print "de weerstand is %s,%s Mega ohm" % (res2) > #elif len(str(res)) > 3: > # res2 = res / 1000 > # print "de weerstand is", res2,"kilo ohm" > #elif len(str(res)) < 4: > # res2 = res > # print "de weerstand is", res2,"ohm" > > i commented it because it doesn't work (yet), when i have a resistance of > 9.9 Giga ohms it says it is 9 giga ohms. it seems to work with natural number, anyway of using decimals insted so that it says : the resistance is 9.9 Giga Ohms instead of 9 ? Others have already explained how to do floating-point rather than integer division. I'm curious to know why you're basing the if tests on the length of the number as a string rather than on the magnitude of the number. Consider for example an input of 0.01. Converted to a string, that is "0.01" which has a length of 4. So the output would be "de weerstand is 0.00001 kilo ohm", which is probably not what you would desire.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
decimal numbers luke.geelen@gmail.com - 2014-02-15 01:18 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 01:19 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:04 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 02:32 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:49 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:17 -0800
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:23 -0700
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:42 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 10:57 -0800
Re: decimal numbers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-15 19:06 +0000
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-15 19:43 +0000
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 14:34 -0700
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-16 02:30 +0000
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-16 13:36 +1100
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:56 +0200
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-15 21:13 +1100
Re: decimal numbers Laurent Pointal <laurent.pointal@free.fr> - 2014-02-15 15:52 +0100
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:20 -0700
Re: decimal numbers wxjmfauth@gmail.com - 2014-02-16 04:19 -0800
csiph-web