By Ryan Wiles
The Python Shell implements a REPL (Record-Eval-Print-Loop) Session allowing you to quickly experiment, investigate data structures as well as seeing the output of each statement.
In your terminal, use the following command to start the Python shell.
Next we’ll try a few classic examples to get your feet wet. I’m not going to explain any details about the syntax in the examples yet. We’re going to go into all of those details in a couple of sections.
Fibonacci was originally investigating how quickly a rabbit population would grow every month. The result of the Fibonacci sequence gives the number of pairs of rabbits at month n. Now, a rational person would note that while it takes into account rabbits being born it doesn’t take into account their expected lifespan. So, for the sake of argument we have to assume that BUNNIES NEVER DIE!
fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2) for i in range(10): print("fib(" + str(i) + ") = " + str(fib(i)))
def fib(n): return n if n < 2 else fib(n-1) + fib(n-2) for i in range(10): print("fib(" + str(i) + ") = " + str(fib(i)))
quit() or Ctrl-D
© 2018 Ryan Wiles