Updated pi.py, did fibonacci series
+16 −1 · 2 files changed
-
Numbers/fibonacci.py+15 −0 -
Numbers/pi.py+1 −1
@@ -0,0 +1,15 @@ +# -*- coding: cp1252 -*- +# Fibonacci Sequence Enter a number and have the +# program generate the Fibonacci sequence to that number +# or to the Nth number + +n = int(raw_input('How many numbers do you need? ')) +series = [1] + +while len(series) < n: + if len(series) == 1: + series.append(1) + else: + series.append(series[-1] + series[-2]) + +print series @@ -4,4 +4,4 @@ import math digits = raw_input('Enter number of digits to round PI to: ') -print round(math.pi, int(digits)) +print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting