[Tutor] Need a little help in formatting print statement

Steven D'Aprano steve at pearwood.info
Sun Dec 7 16:35:53 CET 2014

Hello Anubhav and welcome!

On Sun, Dec 07, 2014 at 07:54:53PM +0530, Anubhav Yadav wrote:

> 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.

If your code is short enough, say, less than 50 lines, please include it 
directly in your email. Some of us are reading and replying to posts at 
a time where it is inconvenient to access the web, or at least parts of 
the web.

> I am supposed to get this <http://i.imgur.com/gi5syL7.png> output:
> If I use the %f formatter, I get this output:

Try using the %r formatter:

py> for x in (1995262.314969, 1995262314968.882812,
...           2818382931264449024.0, 11220184543019653120.0):
...     print( "%r" % x )  # same as print(repr(x))


More information about the Tutor mailing list