Skip to content

Commit

Permalink
organized
Browse files Browse the repository at this point in the history
  • Loading branch information
deimie committed Mar 29, 2022
1 parent 798058c commit 77bc388
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .breakpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"main.py": [
{
"id": "3b53cf6d-bde5-4a6c-a53e-258d8b483d33",
"line": 13,
"version": 209,
"index": 422
}
]
}
}
2 changes: 1 addition & 1 deletion .replit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
language = "python3"
run = "python main.py"
run = ["python3", "weeklyChallenges/week2/factors.py"]
Binary file modified __pycache__/menuy.cpython-38.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import menuy

main_menu = [
["Swap", "swap.py"],
["Christmas Tree", "xmasTree.py"],
["Fibonacci", "fibonacci.py"]
["Swap", "weeklyChallenges/week0/swap.py"],
["Christmas Tree", "weeklyChallenges/week0/xmasTree.py"],
["Fibonacci", "weeklyChallenges/week1/fibonacci.py"],
["InfoDb", "weeklyChallenges/week1/infoDB.py"],
["Fibonacci w/ Class", "weeklyChallenges/week2/fibonacciClass.py"],
["Factorial", "weeklyChallenges/week2/factorial.py"],
["Factors", "weeklyChallenges/week2/factors.py"]
]

border = "=" * 25
Expand Down
1 change: 0 additions & 1 deletion menuy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ def menu(banner, options):
print(f"Invalid choice: {choice}")

menu(banner, options)
0
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 8 additions & 4 deletions fibonacci.py → weeklyChallenges/week1/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ def fibonacci(n):
a=0
b=1
fibList = [0]


# there are no negative nth terms allowed
if n <=0:
print('Input must be greater than 0.')
fibonacci()

fibonacci() # restart the program

# instead of using logic for the whole sequence, it's easier to make the 1st term always return 0.
elif n == 1:
print(fibList)
return

else:
fibList.append(1)

# for loop will go through each number of the sequence and append them into the list.
for i in range(2,n):
c = a + b
a = b
b = c
fibList.append(c)
print(fibList)
print(fibList) # print final result

fibonacci(n)
File renamed without changes.
14 changes: 14 additions & 0 deletions weeklyChallenges/week2/factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class factorial:

def __call__(self, n):
f = 1
for i in range(1, n + 1):
f = f * i
return f


n = int(input("Enter a number:"))

obj = factorial()
f = obj.__call__(n)
print("Factorial is:", f)
13 changes: 13 additions & 0 deletions weeklyChallenges/week2/factors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def factors():
num = int(input("Enter any Number to find its factors: "))
findFactors(num)

def findFactors(number):
print("Factors of a Given Number {0} are:".format(number))

for value in range(1, number + 1):
if number % value == 0:
print("{0}".format(value), end=" ")
print()

factors()
20 changes: 20 additions & 0 deletions weeklyChallenges/week2/fibonacciClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class fibonacci:
def __init__(self):
self.fiboSeq = [0, 1]

def __call__(self, n):
if n < len(self.fiboSeq):
return self.fiboSeq[n]
else:
# Compute the requested Fibonacci number
fib_number = self(n - 1) + self(n - 2)

#Builds List
self.fiboSeq.append(fib_number)
return self.fiboSeq[n]


n = int(input('Type the nth term in the fibonacci sequence: '))
fibonacci_of = fibonacci()
#Prints nth term that user inputed
print(fibonacci_of(n))

0 comments on commit 77bc388

Please sign in to comment.