Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.testing.unittestArgs": ["-v", "-s", ".", "-p", "test_*.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
Binary file added __pycache__/main.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/test_main.cpython-313.pyc
Binary file not shown.
102 changes: 93 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@
n = 3
return [0, 1, 1]
"""
def fibonacci(n: int) -> list[int]:

return []
def fibonacci(num: int) -> list[int]: # what does this line do:
first_fibonacci = 0
second_fibonacci = 1
list_fibo = [first_fibonacci, second_fibonacci]


if num <= 0: #checks if the nth the is not less then 0
return []
elif num == 1: #if the nth term is 1 you must output first_fibonacci
return [first_fibonacci]
else:
while len(list_fibo) < num:
n= list_fibo[- 1] + list_fibo[-2]
list_fibo.append(n)
return list_fibo


"""
Expand All @@ -25,7 +37,16 @@ def fibonacci(n: int) -> list[int]:
return [2, 4, 8, 22, 50, 98]
"""
def even(nums: list[int]) -> list[int]:
return []
count = 0
even_list = []
for i in nums:
if i % 2 == 0:
even_list.append(i)
count = count + 1
even_list.sort()
return even_list




"""
Expand All @@ -37,8 +58,14 @@ def even(nums: list[int]) -> list[int]:
return [27, 17, 3, 1]
"""
def odd(nums: list[int]) -> list[int]:

return []
count = 0
odd_list = []
for i in nums:
if i % 2 == 1:
odd_list.append(i)
count = count + 1
odd_list.sort()
return odd_list[::-1]


"""
Expand All @@ -54,7 +81,38 @@ def odd(nums: list[int]) -> list[int]:
sum(odd) = 4, sum(even) = 2 → returns 'Odd'
"""
def even_vs_odd(nums: list[int]) -> str:
return ""
count = 0
sum_evens = 0
sum_odds = 0
list_even = []
list_odds = []
empty_list = []
for i in nums:
if i % 2 == 0:
list_even.append(i)
sum_evens = sum(list_even)
count = count + 1

for i in nums:
if i % 2 == 1:
list_odds.append(i)
sum_odds = sum(list_odds)
count = count + 1


if sum_evens > sum_odds:
result = 'Even'
elif sum_odds > sum_evens :
result = 'Odd'
else:
return 'Tie'

if list_even == empty_list and list_odds == empty_list:
result = 'Tie'

return result




"""
Expand All @@ -70,7 +128,16 @@ def even_vs_odd(nums: list[int]) -> str:
is_prime(-3) → raises ValueError
"""
def is_prime(n):
return False
if isinstance(n, (list, dict, str)) or n < 0:
raise ValueError
else:
if n % 2 == 1:
result = True
elif n == 2:
result = True
else:
result = False
return result


"""
Expand All @@ -86,4 +153,21 @@ def is_prime(n):
- Look at the pattern of the example carefully.
"""
def generate_email(fullname: str, year: str, campus: str) -> str:
return ""
*name, surname = fullname.split()
name_1 = name[0]
if name_1 == name[0]:
return f'{name_1[0:2].lower()}{surname.lower()[0:3]}{campus}{year[1:4]}@student.wethinkcode.co.za'


return f'{name[0:2]}{surname.lower()[0:3]}{campus}{year[1:4]}@student.wethinkcode.co.za'





print(even([16,9,4,8,12,4]))
# print(odd([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]))
# print(fibonacci(-1))
# print(even_vs_odd([5,3,8]))
# print(generate_email('Oriel Kopano Dibakoane','2027','cpt'))
print(is_prime(0))
6 changes: 4 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from main import *
import unittest
from main import *


class TestFibonacci(unittest.TestCase):

Expand Down Expand Up @@ -98,7 +99,8 @@ def test_generate_email_edge(self):




if __name__ == '__main__':
unittest.main()