# python as pen and paper substitute

Manuel Graune manuel.graune at koeln.de
Tue Apr 6 17:29:43 EDT 2010

```Manuel Graune <manuel.graune at koeln.de> writes:
>
> The use-case is acually fairly simple. The point is to use a python
> source-file as subsitute for scrap-paper (with the opportunity to
> edit what is already written and without illegible handwriting).
> The output should  1) show manually selected python code and comments
> (whatever I think is important), 2) show selected results (final and
> intermediate) and 3) *not* show python code that for someone only
> interested in the calculation and the results (and probably not
> knowing python) would just be "noise" (e. g. "import"-statements,
> actual "print()"-functions, etc.).
>

Just as an additional example, let's assume I'd want to add the area of
to circles.

The source-file would look something like this:
------>snip  source.py   snip<------
#! /usr/bin/python3
from math import pi as PI

code1="""
d1= 3.0
A1= d1**2 * PI / 4.0
"""
exec(code1)
print(code1)
print("Area of Circle 1:\t", A1)

code2="""
d2= 5.0
A2= d2**2 * PI / 4.0
"""
exec(code2)
print(code2)
print("Area of Circle 2:\t", A2)

Sum_Of_Areas= A1 + A2
print("Sum of areas:\t", Sum_Of_Areas)
------->snip<------------------

And the output is:

d1= 3.0
A1= d1**2 * PI / 4.0

Area of Circle 1:        7.06858347058

d2= 5.0
A2= d1**2 * PI / 4.0

Area of Circle 2:        19.6349540849

Sum of areas:    26.7035375555

which can be explained to anyone who knows
basic math and is not at all interested in
python.

> Regards,
>
> Manuel

--
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99

```