Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41605
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Lists and Decimal numbers |
| Date | 2013-03-20 16:52 +0100 |
| Organization | None |
| References | <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3567.1363794723.2939.python-list@python.org> (permalink) |
Ana Dionísio wrote:
> So, I have this script that puts in a list every minute in 24 hours
>
> hour=[]
> i=0
> t=-(1.0/60.0)
> while i<24*60:
> i = i+1
> t = t+(1.0/60.0)
> hour.append([t])
In many cases you can write
for i in range(...):
...
instead of incrementing manually.
> When it is doing the cicle it can have all the decimal numbers, but I need
> to print the result with only 4 decimal numbers
>
> How can I define the number of decimal numbers I want to print in this
> case? For example with 4 decimal numbers, it would print:
>
> 0.0000
> 0.0167
> 0.0333
> ...
>
> Can you help?
>>> for i in range(24*60):
... print "{:.4f}".format(i/60.0)
...
0.0000
0.0167
0.0333
0.0500
[...]
23.9500
23.9667
23.9833
>>>
See also
<http://docs.python.org/2/library/string.html#format-specification-mini-language>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Lists and Decimal numbers Ana Dionísio <anadionisio257@gmail.com> - 2013-03-20 08:27 -0700
Re: Lists and Decimal numbers Wanderer <wanderer@dialup4less.com> - 2013-03-20 08:48 -0700
Re: Lists and Decimal numbers Peter Otten <__peter__@web.de> - 2013-03-20 16:52 +0100
Re: Lists and Decimal numbers Alister <alister.ware@ntlworld.com> - 2013-03-20 19:20 +0000
Re: Lists and Decimal numbers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-20 19:53 +0000
Re: Lists and Decimal numbers Grant Edwards <invalid@invalid.invalid> - 2013-03-20 20:00 +0000
Re: Lists and Decimal numbers Alister <alister.ware@ntlworld.com> - 2013-03-20 20:47 +0000
csiph-web