From 36b723ac242666ae50ccd7d3ca9128911b904345 Mon Sep 17 00:00:00 2001 From: Oluwajoba Okeremi Date: Thu, 12 Mar 2026 21:05:51 -0500 Subject: [PATCH 1/6] changing my name --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..10790747 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -8,7 +8,7 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Oluj" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 1c4139051b0aa1fdb0a7653f1c7d3162ac6a2b2b Mon Sep 17 00:00:00 2001 From: Oluwajoba Okeremi Date: Thu, 12 Mar 2026 21:17:08 -0500 Subject: [PATCH 2/6] introduction --- labs/lab_1/lab_1a.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 10790747..7dbde3c5 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -11,6 +11,7 @@ def main(): name = "Oluj" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") + print("This is my personal introduction from the beginning of the course!") if __name__ == "__main__": main() From 3891fbd89b75b1e77f38d1f661529a8f4d72849b Mon Sep 17 00:00:00 2001 From: OluJJ <66696428+Oluwajoba-Okeremi@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:24:07 -0500 Subject: [PATCH 3/6] Add comment about robot speed variable --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 7dbde3c5..12f56efa 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,4 +1,4 @@ -""" +##"This is to simulate a change made on a robot: robot_speed = 5 # m/s"" lab_1a.py The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 From b81ff3e40839014cc56b6d99b80d77584772b423 Mon Sep 17 00:00:00 2001 From: Oluwajoba Okeremi Date: Thu, 12 Mar 2026 21:34:42 -0500 Subject: [PATCH 4/6] Update lab_1a.py --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 12f56efa..128931f7 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,4 +1,4 @@ -##"This is to simulate a change made on a robot: robot_speed = 5 # m/s"" +##"This is to simulate a change made on a robot: robot_speed = 8# m/s"" lab_1a.py The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 From d8878c802af3bb72189157da0153e488a11d8114 Mon Sep 17 00:00:00 2001 From: Oluwajoba Okeremi Date: Thu, 12 Mar 2026 21:51:18 -0500 Subject: [PATCH 5/6] sanitizing numbers --- labs/lab_1/lab_1b.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..bcaefad9 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -37,6 +37,12 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") +def request_sanitized_number(prompt: str) -> float: + while True: + try: + return float(input(prompt)) + except ValueError: + print("Invalid input. Please enter a valid number.") def main(): print(f"===== Simple Calculator =====") From eef1f5704c872ab7963a81df2206788c746212a5 Mon Sep 17 00:00:00 2001 From: Oluwajoba Okeremi Date: Thu, 12 Mar 2026 22:31:45 -0500 Subject: [PATCH 6/6] fixing 1c and 1d --- labs/lab_1/lab_1c.py | 33 +++++++++----------------------- tests/test_1d.py | 31 ++++++++++++++++++++++++++++++ tests/tests_1c.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 tests/test_1d.py create mode 100644 tests/tests_1c.py diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index 40cf98db..f2853bf7 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -1,14 +1,3 @@ -""" -lab_1c.py - -Given a list of numbers, return the maximum sum of any contiguous subarray of the list. - -Do not assume anything. Account for all edge cases. - -Derived from LeetCode problem: https://leetcode.com/problems/maximum-subarray/ (leetcode medium) -""" - -# TODO: Find and resolve the bug in the following implementation. Create unit tests to verify your fix. def max_subarray_sum(nums: list[int]) -> int: """ Function that takes in a list of integers and returns the maximum sum of any contiguous subarray. @@ -18,22 +7,18 @@ def max_subarray_sum(nums: list[int]) -> int: Returns: int: The maximum sum of any contiguous subarray. + + Raises: + ValueError: If nums is empty. """ + if not nums: + raise ValueError("nums must not be empty") max_current = max_global = nums[0] - - for num in nums: + + for num in nums[1:]: max_current = max(num, max_current + num) - if max_current < max_global: + if max_current > max_global: max_global = max_current - - return max_global - -# Example usage: -def main(): - nums = [-2,1,-3,4,-1,2,1,-5,4] - result = max_subarray_sum(nums) - print(f"Maximum subarray sum: {result}") -if __name__ == "__main__": - main() \ No newline at end of file + return max_global \ No newline at end of file diff --git a/tests/test_1d.py b/tests/test_1d.py new file mode 100644 index 00000000..3cd2ba1c --- /dev/null +++ b/tests/test_1d.py @@ -0,0 +1,31 @@ +import unittest + +def two_sum(nums: list[int], target: int) -> list[int]: + num_to_index = {} + for index, num in enumerate(nums): + complement = target - num + if complement in num_to_index: + return [num_to_index[complement], index] + num_to_index[num] = index + return [] + + +class TestTwoSum(unittest.TestCase): + def test_basic_case(self): + self.assertEqual(two_sum([2, 7, 11, 15], 9), [0, 1]) + + def test_other_case(self): + self.assertEqual(two_sum([3, 2, 4], 6), [1, 2]) + + def test_duplicate_values(self): + self.assertEqual(two_sum([3, 3], 6), [0, 1]) + + def test_negative_numbers(self): + self.assertEqual(two_sum([-1, -2, -3, -4, -5], -8), [2, 4]) + + def test_no_solution_fallback(self): + self.assertEqual(two_sum([1, 2, 3], 100), []) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/tests_1c.py b/tests/tests_1c.py new file mode 100644 index 00000000..94e9f59b --- /dev/null +++ b/tests/tests_1c.py @@ -0,0 +1,45 @@ +import unittest + +def max_subarray_sum(nums: list[int]) -> int: + if not nums: + raise ValueError("nums must not be empty") + + max_current = max_global = nums[0] + + for num in nums[1:]: + max_current = max(num, max_current + num) + if max_current > max_global: + max_global = max_current + + return max_global + + +class TestMaxSubarraySum(unittest.TestCase): + def test_example_case(self): + self.assertEqual(max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]), 6) + + def test_single_positive(self): + self.assertEqual(max_subarray_sum([5]), 5) + + def test_single_negative(self): + self.assertEqual(max_subarray_sum([-5]), -5) + + def test_all_negative(self): + self.assertEqual(max_subarray_sum([-8, -3, -6, -2, -5, -4]), -2) + + def test_all_positive(self): + self.assertEqual(max_subarray_sum([1, 2, 3, 4]), 10) + + def test_mixed_values(self): + self.assertEqual(max_subarray_sum([5, -2, 3, 4]), 10) + + def test_contains_zeroes(self): + self.assertEqual(max_subarray_sum([0, 0, 0]), 0) + + def test_empty_list_raises(self): + with self.assertRaises(ValueError): + max_subarray_sum([]) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file