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
Binary file added __pycache__/system_check.cpython-310.pyc
Binary file not shown.
159 changes: 98 additions & 61 deletions system_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,97 @@
# ==========================================

def get_departure_airport(ticket_string: str):
"""
QUESTION 1
----------------------------------------
Extract the Departure Airport Code from the ticket string.

Format of ticket_string: "FL-JO234-JNB-CPT-2023"

Logic:
- The code is situated between the second and third hyphen (-).
- In the example "FL-JO234-JNB-CPT-2023", the departure is "JNB".

Harder Twist: You cannot use fixed indices (e.g., [10:13]) because the
Flight Number (JO234) can vary in length. You must find it relative to the hyphens.
"""
# TODO: Write your code here
pass
"""
QUESTION 1
----------------------------------------
Extract the Departure Airport Code from the ticket string.

Format of ticket_string: "FL-JO234-JNB-CPT-2023"

Logic:
- The code is situated between the second and third hyphen (-).
- In the example "FL-JO234-JNB-CPT-2023", the departure is "JNB".

Harder Twist: You cannot use fixed indices (e.g., [10:13]) because the
Flight Number (JO234) can vary in length. You must find it relative to the hyphens.
"""
# TODO: Write your code here
fl_class, fl_num, DepAirCode, ArrAirCode, fl_year = ticket_string.split("-")
print(f"The Departure Airport: {DepAirCode}")
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 function should return the departure airport code, but it only prints the value. Add return DepAirCode after the print statement.

Suggested change
print(f"The Departure Airport: {DepAirCode}")
print(f"The Departure Airport: {DepAirCode}")
return DepAirCode

Copilot uses AI. Check for mistakes.

def check_baggage_allowance(ticket_string: str):
"""
QUESTION 2
----------------------------------------
Determine the baggage allowance based on the Flight Class.

Format: The first two letters of the string indicate the class.
Example: "FL-..." starts with "FL".

Logic:
- If starts with 'EC': return "Economy - 20kg"
- If starts with 'BS': return "Business - 40kg"
- If starts with 'FL': return "First Class - 60kg"
- For any other code: return "Standard - 0kg"
"""
# TODO: Write your code here
pass
"""
QUESTION 2
----------------------------------------
Determine the baggage allowance based on the Flight Class.

Format: The first two letters of the string indicate the class.
Example: "FL-..." starts with "FL".

Logic:
- If starts with 'EC': return "Economy - 20kg"
- If starts with 'BS': return "Business - 40kg"
- If starts with 'FL': return "First Class - 60kg"
- For any other code: return "Standard - 0kg"
"""
# TODO: Write your code here
fl_class, fl_num, DepAirCode, ArrAirCode, fl_year = ticket_string.split("-")
print(f"The Flight Class: {fl_class}")

Comment on lines +41 to 42
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 function should determine and return the baggage allowance based on the flight class (e.g., "Economy - 20kg", "Business - 40kg", "First Class - 60kg", or "Standard - 0kg"), but it only prints the flight class. The logic to check the class and return the appropriate allowance string is missing.

Suggested change
print(f"The Flight Class: {fl_class}")
if fl_class.startswith('EC'):
return "Economy - 20kg"
elif fl_class.startswith('BS'):
return "Business - 40kg"
elif fl_class.startswith('FL'):
return "First Class - 60kg"
else:
return "Standard - 0kg"

Copilot uses AI. Check for mistakes.
def validate_flight_number(ticket_string: str):
"""
QUESTION 3
----------------------------------------
Extract the Flight Number (the part between 1st and 2nd hyphen, e.g., "JO234").

Logic:
- If the number portion (e.g., 234) is Even, return "Valid - Northbound"
- If the number portion is Odd, return "Valid - Southbound"
- If the numeric part cannot be converted to a number, return "Invalid Flight"
"""
# TODO: Write your code here
pass
"""
QUESTION 3
----------------------------------------
Extract the Flight Number (the part between 1st and 2nd hyphen, e.g., "JO234").

Logic:
- If the number portion (e.g., 234) is Even, return "Valid - Northbound"
- If the number portion is Odd, return "Valid - Southbound"
- If the numeric part cannot be converted to a number, return "Invalid Flight"
"""
# TODO: Write your code here
fl_class, fl_num, DepAirCode, ArrAirCode, fl_year = ticket_string.split("-")
print(f"The Flight Number: {fl_num}")
flight_digits = []
for i in fl_num:
if i.isdigit:
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.

isdigit is a method and must be called with parentheses: i.isdigit(). Without the parentheses, this always evaluates to True (since the method object is truthy), causing all characters to be appended to the list.

Suggested change
if i.isdigit:
if i.isdigit():

Copilot uses AI. Check for mistakes.
flight_digits.append(i)
print(flight_digits)

Comment on lines +56 to +62
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 function should return "Valid - Northbound", "Valid - Southbound", or "Invalid Flight" based on whether the numeric portion of the flight number is even, odd, or invalid. However, the current implementation only extracts and prints the digits without performing the required logic or returning any value.

Suggested change
print(f"The Flight Number: {fl_num}")
flight_digits = []
for i in fl_num:
if i.isdigit:
flight_digits.append(i)
print(flight_digits)
# Extract digits from flight number
flight_digits = ''.join([i for i in fl_num if i.isdigit()])
if not flight_digits:
return "Invalid Flight"
try:
num = int(flight_digits)
except ValueError:
return "Invalid Flight"
if num % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.



# ==========================================
# SECTION B: ALGORITHMIC LOGIC (MATH)
# ==========================================

def is_leap_year(year: int):
"""
QUESTION 4
----------------------------------------
Determine if a given year is a Leap Year.
This replaces FizzBuzz with harder Modulo logic.

Rules:
1. If the year is evenly divisible by 4, go to step 2. Otherwise, False.
2. If the year is evenly divisible by 100, go to step 3. Otherwise, True.
3. If the year is evenly divisible by 400, True. Otherwise, False.

Return True or False (Boolean).
"""
# TODO: Write your code here
pass

"""
QUESTION 4
----------------------------------------
Determine if a given year is a Leap Year.
This replaces FizzBuzz with harder Modulo logic.

Rules:
1. If the year is evenly divisible by 4, go to step 2. Otherwise, False.
2. If the year is evenly divisible by 100, go to step 3. Otherwise, True.
3. If the year is evenly divisible by 400, True. Otherwise, False.

Return True or False (Boolean).
"""
# TODO: Write your code here
if year % 4 == 0:
pass
else:
return False
if year % 100 == 0:
pass
else:
return False
if year % 400 == 0:
return True
else:
return False
Comment on lines +85 to +96
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.

According to the leap year rules, if the year is divisible by 100, it should proceed to check if it's divisible by 400. However, this implementation returns False when divisible by 100 but not by 400, which is correct, but the logic flow is incorrect. If the year is divisible by 100, it should NOT return True immediately (line 92 is unreachable). The correct logic should check divisibility by 400 and return True/False accordingly, not return True for any year divisible by 100.

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

Copilot uses AI. Check for mistakes.

# ==========================================
# SECTION C: COMPLEX LOGIC & TDD
Expand Down Expand Up @@ -105,4 +125,21 @@ 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:
return "Sensor Error"
elif temp > 2000 or radiation > 500:
return "CRITICAL"
elif 1000 < temp > 2000 and radiation > 100:
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 1000 < temp > 2000 is incorrect. This checks if 1000 < temp AND temp > 2000, which can never be true (temp can't be both greater than 1000 and greater than 2000 means less than 2000). The correct condition should be 1000 <= temp <= 2000 and radiation > 100 to check if temp is between 1000 and 2000 (inclusive) as per the requirements.

Suggested change
elif 1000 < temp > 2000 and radiation > 100:
elif 1000 <= temp <= 2000 and radiation > 100:

Copilot uses AI. Check for mistakes.
return "WARNING"
elif temp < 500:
return "Maintenance Mode"
else:
return "Normal Operation"

get_departure_airport("FL-JO234-JNB-CPT-2023")
check_baggage_allowance("FL-JO234-JNB-CPT-2023")
validate_flight_number("FL-JO234-JNB-CPT-2023")
print(is_leap_year(2000))
print(is_leap_year(2001))
print(is_leap_year(2002))
print(is_leap_year(2016))
Comment on lines +139 to +145
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.

These function calls and test statements should be removed from the module-level code or placed inside a if __name__ == "__main__": block. When this module is imported by test files, these statements will execute automatically, which is undesirable and can interfere with testing.

Suggested change
get_departure_airport("FL-JO234-JNB-CPT-2023")
check_baggage_allowance("FL-JO234-JNB-CPT-2023")
validate_flight_number("FL-JO234-JNB-CPT-2023")
print(is_leap_year(2000))
print(is_leap_year(2001))
print(is_leap_year(2002))
print(is_leap_year(2016))
if __name__ == "__main__":
get_departure_airport("FL-JO234-JNB-CPT-2023")
check_baggage_allowance("FL-JO234-JNB-CPT-2023")
validate_flight_number("FL-JO234-JNB-CPT-2023")
print(is_leap_year(2000))
print(is_leap_year(2001))
print(is_leap_year(2002))
print(is_leap_year(2016))

Copilot uses AI. Check for mistakes.
22 changes: 22 additions & 0 deletions test_reactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest
from system_check import reactor_status
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.

Import of 'reactor_status' is not used.

Suggested change
from system_check import reactor_status

Copilot uses AI. Check for mistakes.

class TestReactor(unittest.TestCase):

def test_negative_checks(self):
self.assertEqual((15, -5), "Sensor Error")

def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")

def test_warning(self):
self.assertEqual((1500, 115), "WARNING")

def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")

def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
Comment on lines +7 to +19
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 assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(1500, 115), "WARNING")

Suggested change
self.assertEqual((15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual((1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
self.assertEqual(reactor_status(15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual(reactor_status(2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual(reactor_status(1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual(reactor_status(250, 35), "Normal Operation")

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +19
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 assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(250, 35), "Normal Operation")

Suggested change
self.assertEqual((15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual((1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
self.assertEqual(reactor_status(15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual(reactor_status(2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual(reactor_status(1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual(reactor_status(250, 35), "Normal Operation")

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +19
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 assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(475, 56), "Maintenance Mode")

Suggested change
self.assertEqual((15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual((1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
self.assertEqual(reactor_status(15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual(reactor_status(2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual(reactor_status(1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual(reactor_status(250, 35), "Normal Operation")

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +19
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 assertEqual method expects the actual value as the first argument and the expected value as the second argument. This test is currently calling assertEqual with a tuple as the first argument instead of calling the reactor_status function. It should be: self.assertEqual(reactor_status(15, -5), "Sensor Error")

Suggested change
self.assertEqual((15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual((1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
self.assertEqual(reactor_status(15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual(reactor_status(2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual(reactor_status(1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual(reactor_status(250, 35), "Normal Operation")

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +19
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 assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(2100, 459), "CRITICAL")

Suggested change
self.assertEqual((15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual((2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual((1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual((475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual((250, 35), "Normal Operation")
self.assertEqual(reactor_status(15, -5), "Sensor Error")
def test_critical(self):
self.assertEqual(reactor_status(2100, 459), "CRITICAL")
def test_warning(self):
self.assertEqual(reactor_status(1500, 115), "WARNING")
def test_maintenance(self):
self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
def test_normal_operation(self):
self.assertEqual(reactor_status(250, 35), "Normal Operation")

Copilot uses AI. Check for mistakes.

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