Skip to content
Open
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
112 changes: 74 additions & 38 deletions system_check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ==========================================
# SECTION A: DATA PARSING (FLIGHT TICKET SYSTEM)
# ==========================================

def get_departure_airport(ticket_string: str):
"""
QUESTION 1
Expand All @@ -17,8 +16,12 @@ def get_departure_airport(ticket_string: str):
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
# # TODO: Write your code here
# pass
Comment on lines +19 to +20
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: the comment has extra leading spaces. The indentation should align with the function body using 4 spaces, not 3 spaces plus 2 extra spaces.

Copilot uses AI. Check for mistakes.
return ticket_string[9] +ticket_string[10] +ticket_string[11]
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 string concatenation with + operator is inefficient and hard to read. Consider using string slicing instead: return ticket_string[9:12]. This is more concise and follows Python best practices for extracting substrings.

Suggested change
return ticket_string[9] +ticket_string[10] +ticket_string[11]
return ticket_string.split('-')[2]

Copilot uses AI. Check for mistakes.
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 implementation uses hardcoded indices which violates the stated requirement: "You cannot use fixed indices (e.g., [10:13]) because the Flight Number (JO234) can vary in length." The correct approach is to find the departure airport by splitting on hyphens: return ticket_string.split('-')[2].

Suggested change
return ticket_string[9] +ticket_string[10] +ticket_string[11]
return ticket_string.split('-')[2]

Copilot uses AI. Check for mistakes.
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 before committing code. This appears to be leftover from testing.

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 @@ -35,27 +38,44 @@ def check_baggage_allowance(ticket_string: str):
- If starts with 'FL': return "First Class - 60kg"
- For any other code: return "Standard - 0kg"
"""
# TODO: Write your code here
pass
# # TODO: Write your code here
# pass
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.

Inconsistent indentation: the comment has extra leading spaces. The indentation should align with the function body using 4 spaces, not 3 spaces plus 2 extra spaces.

Suggested change
# # TODO: Write your code here
# pass
# TODO: Write your code here
# pass

Copilot uses AI. Check for mistakes.
if ticket_string[0]+ticket_string[1]=='EC':
return "Economy - 20kg"
elif ticket_string[0]+ticket_string[1]=='BS':
return "Business - 40kg"
elif ticket_string[0]+ticket_string[1]=='FL':
return "First Class - 60kg"
else:
return "Standard - 0kg"
Comment on lines +43 to +50
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.

String concatenation with + operator is inefficient and hard to read. Consider using string slicing: ticket_string[:2] or the split method as mentioned in the function requirements.

Copilot uses AI. Check for mistakes.
print(check_baggage_allowance("FL-JO234-JNB-CPT-2023"))



Comment on lines +51 to 54
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 before committing code. This appears to be leftover from testing.

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

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").

"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.

Inconsistent formatting: Added extra indentation (8 spaces) before the example string. This line should be aligned with the other lines in the docstring using 4 spaces.

Suggested change
"FL-JO234-JNB-CPT-2023"
"FL-JO234-JNB-CPT-2023"

Copilot uses AI. Check for mistakes.

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
# # TODO: Write your code here
# pass

if ticket_string[7]==2 or 4 or 6 or 8 or 0:
return "Valid - Northbound"
if ticket_string[7]!=2 or 4 or 6 or 8 or 0:
return "Valid - Southbound"
if not ticket_string.isdigit():
return "Invalid Flight"
Comment on lines +67 to +75
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 condition has the same logical error as line 70. Additionally, this logic is flawed because it doesn't properly extract and validate the numeric portion of the flight number. The function should: 1) split the string to get the flight number segment, 2) extract only the numeric portion, 3) check if it's a valid number, and 4) check if it's even or odd.

Suggested change
# # TODO: Write your code here
# pass
if ticket_string[7]==2 or 4 or 6 or 8 or 0:
return "Valid - Northbound"
if ticket_string[7]!=2 or 4 or 6 or 8 or 0:
return "Valid - Southbound"
if not ticket_string.isdigit():
return "Invalid Flight"
import re
# Split the ticket string by hyphens
parts = ticket_string.split('-')
if len(parts) < 2:
return "Invalid Flight"
flight_segment = parts[1]
# Extract numeric portion from flight_segment
match = re.search(r'(\d+)', flight_segment)
if not match:
return "Invalid Flight"
number_str = match.group(1)
try:
number = int(number_str)
except ValueError:
return "Invalid Flight"
if number % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +75
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 condition is logically incorrect. The expression ticket_string[7]==2 or 4 or 6 or 8 or 0 doesn't check if the character equals any of these values. In Python, or 4 is always truthy, making this condition always evaluate to True. The correct approach is: if int(ticket_string[7]) % 2 == 0: to check if the digit is even.

Suggested change
if ticket_string[7]==2 or 4 or 6 or 8 or 0:
return "Valid - Northbound"
if ticket_string[7]!=2 or 4 or 6 or 8 or 0:
return "Valid - Southbound"
if not ticket_string.isdigit():
return "Invalid Flight"
# Extract the flight number between the first and second hyphens
parts = ticket_string.split('-')
if len(parts) < 2:
return "Invalid Flight"
flight_number = parts[1]
# Extract the numeric part from the flight number
numeric_part = ''.join(filter(str.isdigit, flight_number))
if not numeric_part:
return "Invalid Flight"
try:
num = int(numeric_part)
except ValueError:
return "Invalid Flight"
if num % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +75
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 check is applied to the entire ticket string rather than just the numeric portion of the flight number. This will always return False since the ticket string contains hyphens and letters. The validation should be applied only to the extracted numeric portion of the flight number.

Suggested change
# # TODO: Write your code here
# pass
if ticket_string[7]==2 or 4 or 6 or 8 or 0:
return "Valid - Northbound"
if ticket_string[7]!=2 or 4 or 6 or 8 or 0:
return "Valid - Southbound"
if not ticket_string.isdigit():
return "Invalid Flight"
import re
# Extract flight number (between first and second hyphen)
parts = ticket_string.split('-')
if len(parts) < 2:
return "Invalid Flight"
flight_number = parts[1]
# Extract numeric portion from flight number
match = re.search(r'(\d+)', flight_number)
if not match:
return "Invalid Flight"
num_str = match.group(1)
try:
num = int(num_str)
except ValueError:
return "Invalid Flight"
if num % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
print(validate_flight_number("FL-JOABC-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 before committing code. This appears to be leftover from testing.

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

Copilot uses AI. Check for mistakes.


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

def is_leap_year(year: int):
"""
Expand All @@ -71,38 +91,54 @@ def is_leap_year(year: int):

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

# # TODO: Write your code here
# pass
year=12
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 parameter year is immediately overwritten with the hardcoded value 12, making the function always operate on year 12 regardless of input. Remove line 96 to use the actual parameter value.

Suggested change
year=12

Copilot uses AI. Check for mistakes.
a=4
b=100
c=400

if year%a==0:
if year%b==0:
if year%c==0:
return True
else:
return False
else:
return True
else:
return True
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 leap year logic is incorrect. The else branch on line 110 returns True, but it should return False since years not divisible by 4 are not leap years. The correct return value should be False.

Suggested change
return True
return False

Copilot uses AI. Check for mistakes.
Comment on lines +96 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.

These variable names (a, b, c) are not descriptive. Use meaningful names like divisor_four, divisor_hundred, and divisor_four_hundred, or better yet, use the numeric literals directly in the conditions for clarity.

Suggested change
year=12
a=4
b=100
c=400
if year%a==0:
if year%b==0:
if year%c==0:
return True
else:
return False
else:
return True
else:
return True
# Use the function argument 'year' directly
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False

Copilot uses AI. Check for mistakes.

print(is_leap_year(2020))
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 before committing code. This appears to be leftover from testing.

Suggested change
print(is_leap_year(2020))

Copilot uses AI. Check for mistakes.

# ==========================================
# SECTION C: COMPLEX LOGIC & TDD
# ==========================================
# # ==========================================
# # SECTION C: COMPLEX LOGIC & TDD
# # ==========================================

def reactor_status(temp: int, radiation: int):
"""
QUESTION 5 (THE LOGIC MONITOR)
----------------------------------------
Analyze a nuclear reactor's status based on Temperature (C) and Radiation (Sv).
# def reactor_status(temp: int, radiation: int):
# """
# QUESTION 5 (THE LOGIC MONITOR)
# ----------------------------------------
# Analyze a nuclear reactor's status based on Temperature (C) and Radiation (Sv).

TODO: Using TDD, implement tests for the below functionality.
Create `test_reactor.py` with class `TestReactor`.
# TODO: Using TDD, implement tests for the below functionality.
# Create `test_reactor.py` with class `TestReactor`.

Logic Tree:
1. NEGATIVE CHECKS (Invalid Sensors):
- If temp OR radiation is less than 0: return "Sensor Error"
# Logic Tree:
# 1. NEGATIVE CHECKS (Invalid Sensors):
# - If temp OR radiation is less than 0: return "Sensor Error"

2. CRITICAL (Meltdown imminent):
- If temp > 2000 OR radiation > 500: return "CRITICAL"
# 2. CRITICAL (Meltdown imminent):
# - If temp > 2000 OR radiation > 500: return "CRITICAL"

3. WARNING (Unstable):
- If temp is between 1000 and 2000 (inclusive) AND radiation > 100: return "WARNING"
# 3. WARNING (Unstable):
# - If temp is between 1000 and 2000 (inclusive) AND radiation > 100: return "WARNING"

4. MAINTENANCE (Low output):
- If temp < 500: return "Maintenance Mode"
# 4. MAINTENANCE (Low output):
# - If temp < 500: return "Maintenance Mode"

5. NORMAL:
- For all other cases: return "Normal Operation"
"""
# TODO: Write your code here
pass
# 5. NORMAL:
# - For all other cases: return "Normal Operation"
# """
# # TODO: Write your code here
# pass
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 comment appears to contain commented-out code.

Suggested change
# pass

Copilot uses AI. Check for mistakes.