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
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
Binary file added __pycache__/main.cpython-310.pyc
Binary file not shown.
66 changes: 57 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List
import math
"""
The Fibonacci sequence is a series of numbers where each number
is the sum of the two preceding ones, starting from 0 and 1.
Expand All @@ -12,8 +14,18 @@
return [0, 1, 1]
"""
def fibonacci(n: int) -> list[int]:
if not isinstance(n, int):
raise ValueError("n must be int")
if n <= 0:
return []
seq = [0]
if n == 1:
return seq
seq.append(1)
while len(seq) < n:
seq.append(seq[-1] + seq[-2])

return []
return seq


"""
Expand All @@ -24,8 +36,9 @@ 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]:
ev=[ x for x in nums if isinstance(x, int) and x % 2 == 0]
return sorted(ev)


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

return []
od = [x for x in nums if isinstance(x, int) and x % 2 != 0]
return sorted(od, reverse=True)


"""
Expand All @@ -54,7 +67,13 @@ def odd(nums: list[int]) -> list[int]:
sum(odd) = 4, sum(even) = 2 → returns 'Odd'
"""
def even_vs_odd(nums: list[int]) -> str:
return ""
ev_sum = sum(even(nums))
od_sum = sum(odd(nums))
if ev_sum > od_sum:
return "Even"
if od_sum > ev_sum:
return "Odd"
return "Tie"


"""
Expand All @@ -69,8 +88,24 @@ 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)->bool:
if not isinstance(n,int):
raise ValueError("n must be an integer")
if n < 0:
raise ValueError("n must be non-negative")
if n < 2:
return False
if n ==2:
return True
if n % 2==0:
return False
i = 3
limit=int(math.sqrt(n))+1
while i <= limit:
if n % i == 0:
return False
i += 2
return True


"""
Expand All @@ -86,4 +121,17 @@ def is_prime(n):
- Look at the pattern of the example carefully.
"""
def generate_email(fullname: str, year: str, campus: str) -> str:
return ""
fullname_ = fullname.split(" ")
year_=year[1:]
name=fullname_[0][:2]
name = name.lower()
surname=fullname_[-1][:3]
surname=surname.lower()
email=name + surname + campus + year_ + "@student.wethinkcode.co.za"
return email






Binary file added tests/__pycache__/test_main.cpython-310.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class TestGenerateEmail(unittest.TestCase):
def test_generate_email(self):
self.assertEqual(generate_email('Auston Mtabane','2024','jhb'), 'aumtajhb024@student.wethinkcode.co.za')
self.assertEqual(generate_email('Neo Phukubye','2025','jhb'), 'nephujhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email('Kwenzakele Shongwe','2025','jhb'), 'kwshojhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email('Kwenzakele Shongwe','2025','jhb'), 'kwshojhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email('Khatisani Mongwe','2025','jhb'), 'khmonjhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email('Agnes Chauke','2025','jhb'), 'agchajhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email("Karabo Mahlare",'2025','jhb'), 'kamahjhb025@student.wethinkcode.co.za')
self.assertEqual(generate_email("Karabo Mahlare",'2025','jhb'), 'kamahjhb025@student.wethinkcode.co.za')

def test_generate_email_edge(self):
self.assertEqual(generate_email('Oriel Kopano Dibakoane','2027','cpt'), 'ordibcpt027@student.wethinkcode.co.za')
Expand Down