[Tutor] printing puzzlement

Gregor Lingl glingl@aon.at
Sat, 10 Aug 2002 01:49:50 +0200


Rob schrieb:

>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
>
>  
>
Again I'd like to point you to

http://www.oreilly.com/catalog/pythoncook/chapter/

Section 1.9 contains an interesting discussion and some
propositions far a solution to this (more exactly: to a very similar) 
problem.

Gregor