<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.6.1">
</HEAD>
<BODY>
def x():<BR>
... print 'C F'<BR>
... for i in(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100):<BR>
... fahrenheit = (9.0/5.0) * i + 32<BR>
... print (`i` + ' ' + `fahrenheit`)<BR>
<BR>
Simple but look OK,<BR>
<BR>
Johan<BR>
<BR>
<BR>
On Thu, 2005-09-08 at 19:46 -0700, bob wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
<FONT COLOR="#000000">At 04:34 PM 9/8/2005, Goofball223@wmconnect.com wrote:</FONT><BR>
<BLOCKQUOTE TYPE=CITE>
<FONT SIZE="2"><FONT COLOR="#000000">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? </FONT></FONT><BR>
<BR>
<FONT SIZE="2"><FONT COLOR="#000000">def main(): </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> print "This program shows a table of Celsius temperatures and there Fahrenheit equivalents every 10 degrees from 0C to 100C" </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> print "C F" </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> for i in(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100): </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> fahrenheit = (9.0/5.0) * i + 32 </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> print i </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> print " ", </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> print fahrenheit </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000"> </FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#000000">main() </FONT></FONT><BR>
</BLOCKQUOTE>
<BR>
<FONT COLOR="#000000">1 - you are getting C and F on different lines because there is no , after print i. After you fix that you will get:</FONT><BR>
<FONT COLOR="#000000">C F</FONT><BR>
<FONT COLOR="#000000">0 32.0</FONT><BR>
<FONT COLOR="#000000">10 50.0</FONT><BR>
<FONT COLOR="#000000">... similar lines deleted</FONT><BR>
<FONT COLOR="#000000">40 104.0</FONT><BR>
<FONT COLOR="#000000">... similar lines deleted</FONT><BR>
<FONT COLOR="#000000">100 212.0</FONT><BR>
<BR>
<FONT COLOR="#000000">Now the trick is to get things lined up. Here % formatting comes in:</FONT><BR>
<BR>
<FONT COLOR="#000000">print " C F"</FONT><BR>
<FONT COLOR="#000000">...</FONT><BR>
<FONT COLOR="#000000"> print '%3s %5.1f' % (i, farenheit)</FONT><BR>
<BR>
<FONT COLOR="#000000">Giving:</FONT><BR>
<FONT COLOR="#000000"> C F</FONT><BR>
<FONT COLOR="#000000"> 0 32.0</FONT><BR>
<FONT COLOR="#000000"> 10 50.0</FONT><BR>
<FONT COLOR="#000000">etc. </FONT>
<PRE>
<FONT COLOR="#000000">_______________________________________________</FONT>
<FONT COLOR="#000000">Tutor maillist - <A HREF="mailto:Tutor@python.org">Tutor@python.org</A></FONT>
<FONT COLOR="#000000"><A HREF="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</A></FONT>
</PRE>
</BLOCKQUOTE>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<BR>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>