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


Groups > comp.lang.python > #66395 > unrolled thread

decimal numbers

Started byluke.geelen@gmail.com
First post2014-02-15 01:18 -0800
Last post2014-02-16 04:19 -0800
Articles 19 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  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

#66395 — decimal numbers

Fromluke.geelen@gmail.com
Date2014-02-15 01:18 -0800
Subjectdecimal numbers
Message-ID<833583c7-c307-4ebf-9a60-3be146a565b5@googlegroups.com>
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 ?

[toc] | [next] | [standalone]


#66396

FromLuke Geelen <luke.geelen@gmail.com>
Date2014-02-15 01:19 -0800
Message-ID<ec88852e-1384-4aa5-834b-85135be94ab9@googlegroups.com>
In reply to#66395
Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen:
> 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 ?

, wait i have put one %s to much in the print function. this is from a other attempt so please excuse me

[toc] | [prev] | [next] | [standalone]


#66400

From"Frank Millman" <frank@chagford.com>
Date2014-02-15 12:04 +0200
Message-ID<mailman.6976.1392458669.18130.python-list@python.org>
In reply to#66396
"Luke Geelen" <luke.geelen@gmail.com> wrote in message 
news:ec88852e-1384-4aa5-834b-85135be94ab9@googlegroups.com...
> Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen:
> 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)
>
[...]
>
> 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 ?
>

You don't say which version of python you are using.

If you are using python2, an integer divided by an integer always returns an 
integer -

>>> 10/3
3

It was changed in python3 to return a float -

>>> 10/3
3.3333333333333335

You can reproduce the python3 behaviour in python2 by adding a 'future' 
directive -

>>> from __future__ import division
>>> 10/3
3.3333333333333335

HTH

Frank Millman


[toc] | [prev] | [next] | [standalone]


#66405

FromLuke Geelen <luke.geelen@gmail.com>
Date2014-02-15 02:32 -0800
Message-ID<ae0da085-6c41-4166-92d2-92611a990885@googlegroups.com>
In reply to#66400
Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman:
> "Luke Geelen" <luke.geelen@gmail.com> wrote in message 
> 
> news:ec88852e-1384-4aa5-834b-85135be94ab9@googlegroups.com...
> 
> > Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen:
> 
> > 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)
> 
> >
> 
> [...]
> 
> >
> 
> > 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 ?
> 
> >
> 
> 
> 
> You don't say which version of python you are using.
> 
> 
> 
> If you are using python2, an integer divided by an integer always returns an 
> 
> integer -
> 
> 
> 
> >>> 10/3
> 
> 3
> 
> 
> 
> It was changed in python3 to return a float -
> 
> 
> 
> >>> 10/3
> 
> 3.3333333333333335
> 
> 
> 
> You can reproduce the python3 behaviour in python2 by adding a 'future' 
> 
> directive -
> 
> 
> 
> >>> from __future__ import division
> 
> >>> 10/3
> 
> 3.3333333333333335
> 
> 
> 
> HTH
> 
> 
> 
> Frank Millman

how (and where) would i add this rule into a script? by import or the calculation?

[toc] | [prev] | [next] | [standalone]


#66407

From"Frank Millman" <frank@chagford.com>
Date2014-02-15 12:49 +0200
Message-ID<mailman.6978.1392461388.18130.python-list@python.org>
In reply to#66405
"Luke Geelen" <luke.geelen@gmail.com> wrote in message 
news:ae0da085-6c41-4166-92d2-92611a990885@googlegroups.com...
> Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman:
>> "Luke Geelen" <luke.geelen@gmail.com> wrote in message
>>
>> news:ec88852e-1384-4aa5-834b-85135be94ab9@googlegroups.com...
>>
[...]
>>
>> You can reproduce the python3 behaviour in python2 by adding a 'future' 
>> directive -
>>
>> >>> from __future__ import division
>>
>> >>> 10/3
>>
>> 3.3333333333333335
>>
>
> how (and where) would i add this rule into a script? by import or the 
> calculation?

Treat it like any other import - add it as a new line at the top of your 
script.

Frank


[toc] | [prev] | [next] | [standalone]


#66458

FromLuke Geelen <luke.geelen@gmail.com>
Date2014-02-15 09:17 -0800
Message-ID<df9f242f-b438-4159-b605-4be5e937aaec@googlegroups.com>
In reply to#66407
If i do set form thing in my script i get 
Invalide syntax pointing at the last word of the form rule

[toc] | [prev] | [next] | [standalone]


#66461

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-02-15 10:23 -0700
Message-ID<mailman.7011.1392485048.18130.python-list@python.org>
In reply to#66458
On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
> If i do set form thing in my script i get
> Invalide syntax pointing at the last word of the form rule

Please copy and paste the exact code you ran along with the full text
of the exception into your post.  Paraphrasing it like this doesn't
help us help you.

[toc] | [prev] | [next] | [standalone]


#66464

FromLuke Geelen <luke.geelen@gmail.com>
Date2014-02-15 09:42 -0800
Message-ID<9c1b03cb-c607-4784-aaec-78616988c302@googlegroups.com>
In reply to#66461
Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian:
> On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
> 
> > If i do set form thing in my script i get
> 
> > Invalide syntax pointing at the last word of the form rule
> 
> 
> 
> Please copy and paste the exact code you ran along with the full text
> 
> of the exception into your post.  Paraphrasing it like this doesn't
> 
> help us help you.

sorry i made a typo its fixed, thanks a lot

[toc] | [prev] | [next] | [standalone]


#66472

FromLuke Geelen <luke.geelen@gmail.com>
Date2014-02-15 10:57 -0800
Message-ID<877d1ddd-39d8-4ede-8dff-addade1c57cd@googlegroups.com>
In reply to#66464
Op zaterdag 15 februari 2014 18:42:51 UTC+1 schreef Luke Geelen:
> Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian:
> 
> > On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
> 
> > 
> 
> > > If i do set form thing in my script i get
> 
> > 
> 
> > > Invalide syntax pointing at the last word of the form rule
> 
> > 
> 
> > 
> 
> > 
> 
> > Please copy and paste the exact code you ran along with the full text
> 
> > 
> 
> > of the exception into your post.  Paraphrasing it like this doesn't
> 
> > 
> 
> > help us help you.
> 
> 
> 
> sorry i made a typo its fixed, thanks a lot

hey, is it possible to remove the .0 if it is a valua without something behind the poit (like 5.0 gets 5 but 9.9 stays 9.9

[toc] | [prev] | [next] | [standalone]


#66475

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-02-15 19:06 +0000
Message-ID<mailman.7019.1392491207.18130.python-list@python.org>
In reply to#66472
On 15/02/2014 18:57, Luke Geelen wrote:
> Op zaterdag 15 februari 2014 18:42:51 UTC+1 schreef Luke Geelen:
>> Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian:
>>
>>> On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
>>
>>>
>>
>>>> If i do set form thing in my script i get
>>
>>>
>>
>>>> Invalide syntax pointing at the last word of the form rule
>>
>>>
>>
>>>
>>
>>>
>>
>>> Please copy and paste the exact code you ran along with the full text
>>
>>>
>>
>>> of the exception into your post.  Paraphrasing it like this doesn't
>>
>>>
>>
>>> help us help you.
>>
>>
>>
>> sorry i made a typo its fixed, thanks a lot
>
> hey, is it possible to remove the .0 if it is a valua without something behind the poit (like 5.0 gets 5 but 9.9 stays 9.9
>

Thanks for yet more double line spacing and single line paragraphs.  Is 
it too much to ask for you to follow the instructions that you've 
already been given or better yet to use a decent tool?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#66478

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-02-15 19:43 +0000
Message-ID<52ffc365$0$29973$c3e8da3$5496439d@news.astraweb.com>
In reply to#66472
On Sat, 15 Feb 2014 10:57:20 -0800, Luke Geelen wrote:

> hey, is it possible to remove the .0 if it is a valua without something
> behind the poit (like 5.0 gets 5 but 9.9 stays 9.9

Yes, but not easily. First, check the number's fractional part, and if it 
is zero, convert it to an int:

# Here, your value is x
if x % 1 == 0:
    # Exact whole number.
    x = int(x)


But be warned that really big floats are always ints, even if they have a 
decimal point in them! For example:

x = 1.1e20

has a decimal point, but its value is:

110000000000000000000.0

which is a whole number. So perhaps a better way to do this is to operate 
on the number as a string, not as a numeric value:

s = "%s" % x
if s.endswith(".0"):
    s = s[:-2]


If there is anything you don't understand about this code snippet, please 
feel free to ask.

By the way, I see that you are using GoogleGroups to post. GoogleGroups 
has an extremely obnoxious and annoying habit of throwing in blank lines 
between every line of your reply. Could you please read and follow the 
instructions here:

https://wiki.python.org/moin/GoogleGroupsPython


otherwise you are likely to annoy people and may find we stop answering 
your questions. We are volunteers, and aren't being paid to answer your 
questions. If you make it difficult for us, we may just stop.

Thank you in advance.

Any questions, please don't hesitate to ask.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#66485

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-02-15 14:34 -0700
Message-ID<mailman.7024.1392500128.18130.python-list@python.org>
In reply to#66472
On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
> hey, is it possible to remove the .0 if it is a valua without something behind the poit (like 5.0 gets 5 but 9.9 stays 9.9

The ':g' format specifier will trim off trailing zeroes, e.g.:

>>> '{:g}'.format(5.0)
'5'

It also switches to exponential notation if the scale of the number is
greater than the specified precision (default 6):

>>> '{:g}'.format(5000000.0)
'5e+06'

You can read up on string formatting for more details:
http://docs.python.org/3/library/string.html#formatstrings

[toc] | [prev] | [next] | [standalone]


#66501

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-02-16 02:30 +0000
Message-ID<530022b5$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#66485
On Sat, 15 Feb 2014 14:34:45 -0700, Ian Kelly wrote:

> On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen <luke.geelen@gmail.com>
> wrote:
>> hey, is it possible to remove the .0 if it is a valua without something
>> behind the poit (like 5.0 gets 5 but 9.9 stays 9.9
> 
> The ':g' format specifier will trim off trailing zeroes, e.g.:
> 
>>>> '{:g}'.format(5.0)
> '5'

Oh! That's much nicer than my solution. And it even works with %-style 
string interpolation too!

py> "%g" % 23.0
'23'
py> "%g" % 23.1
'23.1'


Even though I didn't ask the question, I learned something from the 
answer. Thank you.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#66502

FromChris Angelico <rosuav@gmail.com>
Date2014-02-16 13:36 +1100
Message-ID<mailman.7034.1392518221.18130.python-list@python.org>
In reply to#66501
On Sun, Feb 16, 2014 at 1:30 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Even though I didn't ask the question, I learned something from the
> answer. Thank you.

Reason #1443694 for mailing lists rather than personal tutoring :) I
love this aspect of them.

ChrisA

[toc] | [prev] | [next] | [standalone]


#66409

From"Frank Millman" <frank@chagford.com>
Date2014-02-15 12:56 +0200
Message-ID<mailman.6979.1392461797.18130.python-list@python.org>
In reply to#66405
"Frank Millman" <frank@chagford.com> wrote in message 
news:ldngnf$c3r$1@ger.gmane.org...
>
> "Luke Geelen" <luke.geelen@gmail.com> wrote in message 
> news:ae0da085-6c41-4166-92d2-92611a990885@googlegroups.com...
>> Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman:
>>> "Luke Geelen" <luke.geelen@gmail.com> wrote in message
>>>
>>> news:ec88852e-1384-4aa5-834b-85135be94ab9@googlegroups.com...
>>>
> [...]
>>>
>>> You can reproduce the python3 behaviour in python2 by adding a 'future' 
>>> directive -
>>>
>>> >>> from __future__ import division
>>>
>>> >>> 10/3
>>>
>>> 3.3333333333333335
>>>
>>
>> how (and where) would i add this rule into a script? by import or the 
>> calculation?
>
> Treat it like any other import - add it as a new line at the top of your 
> script.
>

Actually I did not answer that very accurately. From the documentation -

"""
A future statement must appear near the top of the module. The only lines 
that can appear before a future statement are:

    the module docstring (if any),
    comments,
    blank lines, and
    other future statements.
"""

Frank


[toc] | [prev] | [next] | [standalone]


#66403

FromChris Angelico <rosuav@gmail.com>
Date2014-02-15 21:13 +1100
Message-ID<mailman.6977.1392459209.18130.python-list@python.org>
In reply to#66396
On Sat, Feb 15, 2014 at 9:04 PM, Frank Millman <frank@chagford.com> wrote:
> If you are using python2, an integer divided by an integer always returns an
> integer -
>
>>>> 10/3
> 3
>
> It was changed in python3 to return a float -
>
>>>> 10/3
> 3.3333333333333335
>
> You can reproduce the python3 behaviour in python2 by adding a 'future'
> directive -
>
>>>> from __future__ import division
>>>> 10/3
> 3.3333333333333335
>

Conversely, you can get an integer result by using floor division:

>>> 10//3
3

ChrisA

[toc] | [prev] | [next] | [standalone]


#66446

FromLaurent Pointal <laurent.pointal@free.fr>
Date2014-02-15 15:52 +0100
Message-ID<52ff7f1f$0$2128$426a74cc@news.free.fr>
In reply to#66395
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 ?

Seem you are using Python2, if res is an integer the division by an integer 
values produce an integer result (changed in Python3), so you loose the 
decimal part.

Try dividing by floating point numbers, like res2 = res / 1000.


Note: should take a lok at the log10() function from math module.

(with Python3)

In [1]: from math import log10

In [2]: r = 132828378723

In [3]: int(log10(r))
Out[3]: 11

In [4]: r / 10**int(log10(r))
Out[4]: 1.32828378723

A+
Laurent.

[toc] | [prev] | [next] | [standalone]


#66460

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-02-15 10:20 -0700
Message-ID<mailman.7010.1392484878.18130.python-list@python.org>
In reply to#66395
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.

[toc] | [prev] | [next] | [standalone]


#66528

Fromwxjmfauth@gmail.com
Date2014-02-16 04:19 -0800
Message-ID<827289f9-9220-4501-addb-009618a017af@googlegroups.com>
In reply to#66395
Without any warranty.

>>> def z(r):
...     # r: int > 0
...     t = log10(r)
...     if t >= 12.0:
...         prefix = ''
...         prefix2 = ''
...     elif t >= 9.0:
...         prefix = 'giga'
...         prefix2 = 'G'
...         r = r / 1.0e9
...     elif t >= 6.0:
...         prefix = 'mega'
...         prefix2 = 'M'
...         r = r / 1.0e6
...     elif t >= 3.0:
...         prefix = 'kilo-'  # Netherlands std?
...         prefix2 = 'k'
...         r = r / 1.0e3
...     else:
...         prefix = ''
...         prefix2 = ''
... 
...     # correct for this language (Dutch?) ?
...     # kept as illustrative example
...     if r >= 2:
...         suffix = 's'
...     else:
...         suffix = ''
...     
...     # '.13g' to "cover the ranges" while "keeping precision"
...     num = format(r, '.13g')
...     s = 'de weerstand is ' + num + ' ' + prefix + 'ohm' + suffix
...     s = s + ' , R = ' + num + ' ' + prefix2 + 'Ω'
...     return s
...     
>>> a = [1, 2, 9, 20, 300, 1000 - 1, 1000, 1000 + 1, 2000, \
...     1000000 - 1, 1000000, 1000000 + 1, \
...     1000000000 - 1, 1000000000, 1000000000 + 1, 11123456789]
>>> 
>>> for e in a:
...     print(e, '-', z(e))
...     
1 - de weerstand is 1 ohm , R = 1 Ω
2 - de weerstand is 2 ohms , R = 2 Ω
9 - de weerstand is 9 ohms , R = 9 Ω
20 - de weerstand is 20 ohms , R = 20 Ω
300 - de weerstand is 300 ohms , R = 300 Ω
999 - de weerstand is 999 ohms , R = 999 Ω
1000 - de weerstand is 1 kilo-ohm , R = 1 kΩ
1001 - de weerstand is 1.001 kilo-ohm , R = 1.001 kΩ
2000 - de weerstand is 2 kilo-ohms , R = 2 kΩ
999999 - de weerstand is 999.999 kilo-ohms , R = 999.999 kΩ
1000000 - de weerstand is 1 megaohm , R = 1 MΩ
1000001 - de weerstand is 1.000001 megaohm , R = 1.000001 MΩ
999999999 - de weerstand is 999.999999 megaohms , R = 999.999999 MΩ
1000000000 - de weerstand is 1 gigaohm , R = 1 GΩ
1000000001 - de weerstand is 1.000000001 gigaohm , R = 1.000000001 GΩ
11123456789 - de weerstand is 11.123456789 gigaohms , R = 11.123456789 GΩ

jmf

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web