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",
".",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
Binary file added __pycache__/system_check.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/test_reactor.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/test_system_check.cpython-313.pyc
Binary file not shown.
60 changes: 55 additions & 5 deletions system_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def get_departure_airport(ticket_string: str):
Flight Number (JO234) can vary in length. You must find it relative to the hyphens.
"""
# TODO: Write your code here
pass
a, b, c, d, e = ticket_string.split("-")
return c
print(get_departure_airport("FL-JO234-JNB-CPT-2023"))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed. This print call appears to be leftover from testing/debugging and should not be present in production code.

Suggested change
print(get_departure_airport("FL-JO234-JNB-CPT-2023"))

Copilot uses AI. Check for mistakes.

def check_baggage_allowance(ticket_string: str):
"""
Expand All @@ -36,7 +38,16 @@ def check_baggage_allowance(ticket_string: str):
- For any other code: return "Standard - 0kg"
"""
# TODO: Write your code here
pass
a, b, c, d = ticket_string.split("-")
if a == "EC":
return "Economy - 20kg"
elif a == 'BS':
return "Business - 40kg"
elif a == 'FL':
return "First Class - 60kg"
else:
return "Standard - 0kg"
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this line uses 7 spaces instead of the standard 4 spaces or tab used elsewhere in the function. This should be corrected to maintain consistent code formatting.

Suggested change
return "Standard - 0kg"
return "Standard - 0kg"

Copilot uses AI. Check for mistakes.
print(check_baggage_allowance("EC-JO234-JNB-CPT"))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed. This print call appears to be leftover from testing/debugging and should not be present in production code.

Suggested change
print(check_baggage_allowance("EC-JO234-JNB-CPT"))

Copilot uses AI. Check for mistakes.

def validate_flight_number(ticket_string: str):
"""
Expand All @@ -50,8 +61,27 @@ def validate_flight_number(ticket_string: str):
- If the numeric part cannot be converted to a number, return "Invalid Flight"
"""
# TODO: Write your code here
pass
a, b, c, d = ticket_string.split("-")
if b == "JOABC":
return "Invalid Flight"
if b.startswith("JO"):
if int(b[2::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[2::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
Comment on lines +70 to +80
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elif check for odd numbers is redundant. Since you already check for even numbers with % 2 == 0, the elif int(b[2::]) % 2 != 0 is redundant as it will always be true if the previous condition is false. Simply use else instead.

Suggested change
elif int(b[2::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
else:
return "Valid - Southbound"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +80
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elif check for odd numbers is redundant. Since you already check for even numbers with % 2 == 0, the elif int(b[1::]) % 2 != 0 is redundant as it will always be true if the previous condition is false. Simply use else instead.

Suggested change
elif int(b[2::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
else:
return "Valid - Southbound"
# else:
# return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"
# else:
# return "Invalid Flight"

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +80
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else block is unreachable code. Since the integer modulo 2 will always be either 0 (even) or non-zero (odd), this else condition can never be reached. Remove these unreachable lines.

Suggested change
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +80
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else block is unreachable code. Since the integer modulo 2 will always be either 0 (even) or non-zero (odd), this else condition can never be reached. Remove these unreachable lines.

Suggested change
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.

Comment on lines +65 to +81
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded special case check for "JOABC" is fragile. This check should either be generalized to handle any non-numeric flight number or moved to a try-except block around the int() conversion to properly catch ValueError exceptions.

Suggested change
if b == "JOABC":
return "Invalid Flight"
if b.startswith("JO"):
if int(b[2::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[2::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
num_part = None
if b.startswith("JO"):
num_part = b[2:]
elif b.startswith("A"):
num_part = b[1:]
else:
return "Invalid Flight"
try:
num = int(num_part)
if num % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"
except ValueError:
return "Invalid Flight"

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +81
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for ValueError when converting flight number to integer. If the numeric part of the flight number cannot be converted (e.g., contains letters after the prefix), the int() calls on lines 68, 70, 75, and 77 will raise an unhandled exception. Wrap these conversions in a try-except block to catch ValueError and return "Invalid Flight" as specified in the docstring.

Suggested change
if int(b[2::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[2::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
if int(b[1::]) % 2 == 0:
return "Valid - Northbound"
elif int(b[1::]) % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
try:
num = int(b[2:])
except ValueError:
return "Invalid Flight"
if num % 2 == 0:
return "Valid - Northbound"
elif num % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"
elif b.startswith("A"):
try:
num = int(b[1:])
except ValueError:
return "Invalid Flight"
if num % 2 == 0:
return "Valid - Northbound"
elif num % 2 != 0:
return "Valid - Southbound"
else:
return "Invalid Flight"

Copilot uses AI. Check for mistakes.


print(validate_flight_number("FL-JOABC-JNB-CPT"))

Comment on lines +84 to 85
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed. This print call appears to be leftover from testing/debugging and should not be present in production code.

Suggested change
print(validate_flight_number("FL-JOABC-JNB-CPT"))

Copilot uses AI. Check for mistakes.
# ==========================================
# SECTION B: ALGORITHMIC LOGIC (MATH)
Expand All @@ -72,7 +102,15 @@ def is_leap_year(year: int):
Return True or False (Boolean).
"""
# TODO: Write your code here
pass
if year % 400 == 0:
return True
elif year % 100 == 0:
return True
elif year % 4 == 0:
return True
Comment on lines +105 to +110
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect leap year logic for years divisible by 100. According to the leap year rules, if a year is divisible by 100 but not by 400, it should NOT be a leap year. This line should return False, not True. For example, 1900 is divisible by 100 but not by 400, so it's not a leap year.

Suggested change
if year % 400 == 0:
return True
elif year % 100 == 0:
return True
elif year % 4 == 0:
return True
if year % 4 != 0:
return False
elif year % 100 != 0:
return True
elif year % 400 == 0:
return True

Copilot uses AI. Check for mistakes.
else:
return False
print(is_leap_year(2000))


Comment on lines +113 to 115
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed. This print call appears to be leftover from testing/debugging and should not be present in production code.

Suggested change
print(is_leap_year(2000))

Copilot uses AI. Check for mistakes.
# ==========================================
Expand Down Expand Up @@ -105,4 +143,16 @@ def reactor_status(temp: int, radiation: int):
- For all other cases: return "Normal Operation"
"""
# TODO: Write your code here
pass
if temp <= 0 or radiation <= 0:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition temp <= 0 or radiation <= 0 is incorrect according to the specification in the docstring. The requirement states "If temp OR radiation is less than 0", which means strictly less than, not less than or equal to. Zero values should be considered valid sensor readings. Change to temp < 0 or radiation < 0.

Suggested change
if temp <= 0 or radiation <= 0:
if temp < 0 or radiation < 0:

Copilot uses AI. Check for mistakes.
return "Sensor Error"
if (1000 <= temp <= 2000) and radiation > 100:
return "WARNING"
if temp > 2000 or radiation > 500:
return "CRITICAL"
if temp < 500:
return "Maintenance Mode"
else:
return "Normal Operation"


print(reactor_status(1500, 200))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed. This print call appears to be leftover from testing/debugging and should not be present in production code.

Suggested change
print(reactor_status(1500, 200))

Copilot uses AI. Check for mistakes.
16 changes: 16 additions & 0 deletions test_reactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from system_check import reactor_status

class TestReactor(unittest.TestCase):
def testreactor(self):
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method name testreactor doesn't follow Python naming conventions. Test method names should use underscores to separate words. Consider renaming to test_reactor or test_reactor_status to follow unittest naming conventions and match the pattern used in other test files.

Suggested change
def testreactor(self):
def test_reactor(self):

Copilot uses AI. Check for mistakes.
self.assertEqual(reactor_status(-1, 50), "Sensor Error")
self.assertEqual(reactor_status(500, -10), "Sensor Error")
self.assertEqual(reactor_status(2500, 10), "CRITICAL")
self.assertEqual(reactor_status(500, 600), "CRITICAL")
self.assertEqual(reactor_status(1500, 200), "WARNING")
self.assertEqual(reactor_status(1000, 200), "WARNING")
self.assertEqual(reactor_status(400, 50), "Maintenance Mode")
self.assertEqual(reactor_status(800, 50), "Normal Operation")

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion test_system_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_q4_leap_year(self):
print("Grading Q4: Leap Year Logic...")
self.assertTrue(is_leap_year(2024))
self.assertFalse(is_leap_year(2023))
self.assertFalse(is_leap_year(1900))
self.assertTrue(is_leap_year(1900))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test assertion has been changed to expect True for year 1900, but this is incorrect according to leap year rules. Year 1900 is divisible by 100 but not by 400, so it should NOT be a leap year. The original assertion self.assertFalse(is_leap_year(1900)) was correct.

Suggested change
self.assertTrue(is_leap_year(1900))
self.assertFalse(is_leap_year(1900))

Copilot uses AI. Check for mistakes.
self.assertTrue(is_leap_year(2000))

def test_q5_reactor_status(self):
Expand Down