Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
"""
The Fibonacci sequence is a series of numbers where each number
The Fibonacci sequence is a series of numbers where each number
is the sum of the two preceding ones, starting from 0 and 1.
The sequence looks like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

The function below receives an integer n, which represents the n-th term
The function below receives an integer n, which represents the n-th term
of the sequence, and must return a list from the first value up to the n-th term.

Example:
n = 3
return [0, 1, 1]
"""


def fibonacci(n: int) -> list[int]:
if n <= 0:
return []
if n == 1:
return [0]
if n == 2:
return [0, 1]

return []
sequence = fibonacci(n - 1)
sequence.append(sequence[-1] + sequence[-2])
return sequence


"""
Expand All @@ -24,8 +34,14 @@ def fibonacci(n: int) -> list[int]:
nums = [1, 3, 2, 27, 50, 17, 8, 4, 98, 22]
return [2, 4, 8, 22, 50, 98]
"""
def even(nums: list[int]) -> list[int]:
return []


def even(nums: list[int]) -> list[int]:
even_list = []
for num in nums:
if num % 2 == 0:
even_list.append(num)
return sorted(even_list)


"""
Expand All @@ -36,9 +52,14 @@ def even(nums: list[int]) -> list[int]:
nums = [1, 3, 2, 27, 50, 17, 8, 4, 98, 22]
return [27, 17, 3, 1]
"""
def odd(nums: list[int]) -> list[int]:

return []

def odd(nums: list[int]) -> list[int]:
odd_list = []
for num in nums:
if num % 2 != 0:
odd_list.append(num)
return sorted(odd_list)[::-1]


"""
Expand All @@ -53,8 +74,12 @@ def odd(nums: list[int]) -> list[int]:
nums = [1, 2, 3]
sum(odd) = 4, sum(even) = 2 → returns 'Odd'
"""


def even_vs_odd(nums: list[int]) -> str:
return ""
sum_even = sum([num for num in nums if num % 2 == 0])
sum_odd = sum([num for num in nums if num % 2 != 0])
return "Tie" if sum_even == sum_odd else "Even" if sum_even > sum_odd else "Odd"


"""
Expand All @@ -69,8 +94,17 @@ def even_vs_odd(nums: list[int]) -> str:
is_prime(10) → False
is_prime(-3) → raises ValueError
"""
def is_prime(n):
return False


def is_prime(n: int) -> bool:
if not isinstance(n, int) or n < 0:
raise ValueError("")
if n == 0:
return False
for i in range(2, n // 2 + 1):
if n % i == 0:
return False
return True


"""
Expand All @@ -85,5 +119,12 @@ def is_prime(n):
- Use lowercase letters.
- Look at the pattern of the example carefully.
"""


def generate_email(fullname: str, year: str, campus: str) -> str:
return ""
year = year.strip()
campus = campus.strip()
fullname = fullname.strip()
user_name = f"{fullname.split()[0].strip()[:2].lower()}{fullname.split()[-1].strip()[:3].lower()}{campus}{year[1:]}"

return f"{user_name}@student.wethinkcode.co.za"