From e1c50c5fd68caa11ab452d590ede0d1a791da815 Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Sun, 18 Oct 2020 14:26:13 +0530 Subject: [PATCH 1/2] nth Fibonacci number --- mathgenerator/mathgen.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 44218e6..d632bef 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -3,7 +3,7 @@ import math import fractions genList = [] - +GOLDEN_RATIO = (1 + math.sqrt(5))/2 # || Generator class class Generator: @@ -920,6 +920,16 @@ def volumeSphereFunc(maxRadius = 100): ans=(4*math.pi/3)*r*r*r solution = f"{ans} m^3" return problem,solution + +def nthFibonacciNumber(maxN = 100): + n = random.randint(1,maxN) + problem = f"What is the {n}th Fibonacci number?" + ans = round((math.pow(GOLDEN_RATIO,n) - math.pow(-GOLDEN_RATIO,-n))/(math.sqrt(5))) + solution = f"{ans}" + return problem, solution + + + # || Class Instances # Format is: @@ -986,3 +996,4 @@ sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles dataSummary = Generator("Mean,Standard Deviation,Variance", 59, "a,b,c", "Mean:a+b+c/3,Std,Var", dataSummaryFunc) surfaceAreaSphereGen = Generator("Surface Area of Sphere", 59, "Surface area of sphere with radius = a units is","d units^2", surfaceAreaSphere) volumeSphere=Generator("Volume of Sphere",60,"Volume of sphere with radius r m = ","(4*pi/3)*r*r*r",volumeSphereFunc) +nthFibonacciNumberGen = Generator("nth Fibonacci number", 61, "What is the nth Fibonacci number", "Fn", nthFibonacciNumber) \ No newline at end of file From 127b73abe86b9b21946006b1d37fa2f6ac7b3233 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Sun, 18 Oct 2020 22:38:28 -0400 Subject: [PATCH 2/2] Made GOLDEN_RATIO local --- mathgenerator/mathgen.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index d632bef..282ae41 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -3,7 +3,6 @@ import math import fractions genList = [] -GOLDEN_RATIO = (1 + math.sqrt(5))/2 # || Generator class class Generator: @@ -922,9 +921,10 @@ def volumeSphereFunc(maxRadius = 100): return problem,solution def nthFibonacciNumber(maxN = 100): + golden_ratio = (1 + math.sqrt(5))/2 n = random.randint(1,maxN) problem = f"What is the {n}th Fibonacci number?" - ans = round((math.pow(GOLDEN_RATIO,n) - math.pow(-GOLDEN_RATIO,-n))/(math.sqrt(5))) + ans = round((math.pow(golden_ratio,n) - math.pow(-golden_ratio,-n))/(math.sqrt(5))) solution = f"{ans}" return problem, solution @@ -996,4 +996,4 @@ sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles dataSummary = Generator("Mean,Standard Deviation,Variance", 59, "a,b,c", "Mean:a+b+c/3,Std,Var", dataSummaryFunc) surfaceAreaSphereGen = Generator("Surface Area of Sphere", 59, "Surface area of sphere with radius = a units is","d units^2", surfaceAreaSphere) volumeSphere=Generator("Volume of Sphere",60,"Volume of sphere with radius r m = ","(4*pi/3)*r*r*r",volumeSphereFunc) -nthFibonacciNumberGen = Generator("nth Fibonacci number", 61, "What is the nth Fibonacci number", "Fn", nthFibonacciNumber) \ No newline at end of file +nthFibonacciNumberGen = Generator("nth Fibonacci number", 61, "What is the nth Fibonacci number", "Fn", nthFibonacciNumber)