... 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` + ' ' + `fahrenheit`)
Simple but look OK,
Johan
On Thu, 2005-09-08 at 19:46 -0700, bob wrote:
At 04:34 PM 9/8/2005, [EMAIL PROTECTED] 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
main()
1 - you are getting C and F on different lines because there is no , after print i. After you fix that you will get:
C F
0 32.0
10 50.0
... similar lines deleted
40 104.0
... similar lines deleted
100 212.0
Now the trick is to get things lined up. Here % formatting comes in:
print " C F"
...
print '%3s %5.1f' % (i, farenheit)
Giving:
C F
0 32.0
10 50.0
etc._______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
|
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor