From e7d02e0e92e07b1bea0a791cee37f9af75cdfafa Mon Sep 17 00:00:00 2001 From: hellerve Date: Sat, 11 Jul 2015 23:23:21 +0200 Subject: [PATCH] Added another example --- README.md | 21 ++++++++++++++++++++- examples/fib.py | 13 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/fib.py diff --git a/README.md b/README.md index a13c9d3..e9b14d8 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,28 @@ And you're good to go! Easy! -````python +```python import improved improved.callIMP("n := 5") # this will return a dictionary containing the key/value pair n/5 ``` + +For a less contrived example, let's calculate the nth fibonacci number +where n is user input: + +```python +import improved + +x = """ + n := read; + fib := 1; + while n > 1 do + fib := n * fib; + n := n -1 + end; + write fib +""" + +improved.callIMP(x) +``` diff --git a/examples/fib.py b/examples/fib.py new file mode 100644 index 0000000..9cfdaa3 --- /dev/null +++ b/examples/fib.py @@ -0,0 +1,13 @@ +import improved + +x = """ + n := read; + fib := 1; + while n > 1 do + fib := n * fib; + n := n -1 + end; + write fib +""" + +improved.callIMP(x)