forked from Workshops/How-To-Git-Started
initial commit
This commit is contained in:
commit
075644011a
6
factorial.py
Normal file
6
factorial.py
Normal file
@ -0,0 +1,6 @@
|
||||
def factorial(num):
|
||||
if not ((num >= 0) and (num % 1 == 0)):
|
||||
raise Exception("Number can't be floating point or negative.")
|
||||
return 1 if num == 0 else num * factorial(num - 1)
|
||||
|
||||
print(factorial(6))
|
12
fibonacci.py
Normal file
12
fibonacci.py
Normal file
@ -0,0 +1,12 @@
|
||||
def fibonacci(n):
|
||||
if n <= 0:
|
||||
return [0]
|
||||
|
||||
sequence = [0, 1]
|
||||
while len(sequence) <= n:
|
||||
next_value = sequence[len(sequence) - 1] + sequence[len(sequence) - 2]
|
||||
sequence.append(next_value)
|
||||
|
||||
return sequence
|
||||
|
||||
print(fibonacci(7))
|
Loading…
Reference in New Issue
Block a user