<br><br><div><span class="gmail_quote">On 08/09/05, <b class="gmail_sendername"><a href="mailto:andrade1@umbc.edu">andrade1@umbc.edu</a></b> &lt;<a href="mailto:andrade1@umbc.edu">andrade1@umbc.edu</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
below is my program. what i would like to do is to get the last line to<br>print the number of years that the user enters and also the principal</blockquote><div><br>
There are a couple (at least!) of ways to get the values into the string that you print.<br>
<br>
The first way is to pass several values to the print command:<br>
<br>
&nbsp;&nbsp;&nbsp; print &quot;The value in&quot;, years, &quot;is&quot;, principal<br>
<br>
Another way is to use placeholders:<br>
&nbsp;&nbsp; print &quot;The value in %d years is %.2f&quot; % (years, principal)<br>
<br>
The placeholders (shown by the % sign) get replaced by the variables in
the list, in order. &quot;%d&quot; means format the value as an integer. &quot;%.2f&quot;
means format it as a floating point value with two decimal places. See
<a href="http://diveintopython.org/native_data_types/formatting_strings.html">http://diveintopython.org/native_data_types/formatting_strings.html</a> for
more details.<br>
<br>
You could replace the main bit of the program with a single line, if you're feeling brave!<br>
<br>
&nbsp;&nbsp; principal = input(&quot;Enter the initial principal: &quot;)<br>
&nbsp;&nbsp; apr = input(&quot;Enter the annual interest rate: &quot;)<br>
&nbsp;&nbsp; years = input(&quot;Enter the number of years: &quot;)<br>
&nbsp;&nbsp; print &quot;The value in %d years will be %.2f&quot; % (years, principal * (1 + apr)**years)<br>
<br>
Hope this is useful!<br>
<br>
Olly<br>
<br>
<br>
<br>
<br>
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"># A program to compute the value of an investment<br># years into the future<br><br>
def main():<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;This program calculates the future value of an investment over<br>years&quot;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;principal = input(&quot;Enter the initial principal: &quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;apr = input(&quot;Enter the annual interest rate: &quot;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;years = input(&quot;Enter the number of years: &quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for i in range(10):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;principal = principal * (1 + apr)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;The value in years is&quot;, principal<br><br>main()<br><br>
<br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor
</a><br></blockquote></div><br>