[Tutor] printing puzzlement
Rob
rob@uselesspython.com
Fri, 9 Aug 2002 17:05:01 -0500
I decided to see if I could convert a simple amortization schedule program
written in C++ into something similar written in Python, because I thought
the explanation would make for some interesting Useless Python material.
Most of it is simple enough, but I'm puzzled about one part.
As seen in the C++ code snippet here, calculations are performed in the
middle of the display of each line of output. Does anyone know of a good way
to reproduce similar behavior in a Python program?
// Display the amortization schedule
cout <<
"Pmt # Cur. Prin. Payment Int. Paid Rem. Prin." << endl;
cout <<
"----- ---------- ------- --------- ----------" << endl;
for (int index = 0; index < numPayments; index++)
{
cout << setw(5) << right << (index + 1);
cout << setw(12) << right << fixed << setprecision(2) << principle;
cout << setw(9) << right << fixed << amtPayment;
float interest = (float (int (principle * monthRate * 100) ) ) / 100.0;
cout << setw(11) << right << fixed << interest;
principle = principle + interest - amtPayment;
cout << setw(12) << right << fixed << principle;
cout << endl;
}
Rob