[Tutor] Need a little help in formatting print statement
Anubhav Yadav
anubhav1691 at gmail.com
Sun Dec 7 15:24:53 CET 2014
I am trying to solve the CS1 Python
<http://cse.msu.edu/~cse231/PracticeOfComputingUsingPython/> Exercises.
The first exercise calculates the energy released from an earthquake based
on it's ritcher scale.
I wrote the code. Here <http://pastebin.com/nXjxCZWJ> is the code.
I am supposed to get this <http://i.imgur.com/gi5syL7.png> output:
If I use the %f formatter, I get this output:
Ritcher Scale Energy TNT
1.0 1995262.314969 0.0005
5.0 1995262314968.882812 476.8791
9.1 2818382931264449024.000000 673609687.2047
9.2 3981071705534952960.000000 951498973.5982
9.5 11220184543019653120.000000 2681688466.3049
and If I use the %e or %g format specifier I get this:
Ritcher Scale Energy TNT
1.0 1.99526e+06 0.0005
5.0 1.99526e+12 476.8791
9.1 2.81838e+18 673609687.2047
9.2 3.98107e+18 951498973.5982
9.5 1.12202e+19 2681688466.3049
In the sample output given by the exercise, the first two values do not use
the scientific notation. So either they are not using a loop to print the
table, or there is a format specifier that prints the floating value in
scientific notation only if some condition is checked.
I know there is a String function called format with which I can achieve
great string formatting but I want to stick with the old C ways of
formatting for now.
Any suggestions would be greatly appreciated.
--
Regards,
Anubhav Yadav
KPIT Technologies,
Pune.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141207/f315b394/attachment.html>
More information about the Tutor
mailing list