[Tutor] making a table
ml.cyresse at gmail.com
Fri Sep 9 12:25:14 CEST 2005
Just a quick thing -
> for i in (0,10, 20, 30, 40, 50, 60, 70, 80, 90, 100):
Have you used range() before?
for i in range(10):
It's handy for situations like yours. Also, you could use it like this -
zeroToNine = range(10)
for i in zeroToNine:
..Just a quick mention that range(x) counts up to, but not including
x. ( There's good reasons for this, which someone can explain if
Also, by default it starts at zero, and increases by 1. You can change
i.e. to create a list from 5 to 50 in increments of 5 -
zeroToFifty = range(start = 5, stop = 55, step = 5)
Remember, it'll count up to but not including stop, so if you tell it
to count to two hundred in steps of 10, it'll count to 190, counting
to 16 by steps of 2 will count to 14. So always set it one step value
above what you want.
(start defaults to 0, step defaults to 1, hence you can just use
range(stop = 100) or
range(100) for short.)
You're looking good, however.
On 9/9/05, Goofball223 at wmconnect.com <Goofball223 at wmconnect.com> wrote:
> I would like to construct a table for my program but it does not seem to be
> coming out evenly. Could someone please let me know what to do so that
> everything will work out correctly?
> def main():
> print "This program shows a table of Celsius temperatures and there
> Fahrenheit equivalents every 10 degrees from 0C to 100C"
> print "C F"
> for i in(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100):
> fahrenheit = (9.0/5.0) * i + 32
> print i
> print " ",
> print fahrenheit
> Tutor maillist - Tutor at python.org
More information about the Tutor